How to Add a Comment in a VBA in Excel?
Last Updated :
14 Feb, 2023
VBA Macro is for developers. Macro is a piece of code written in VBA. VBA is Microsoft’s programming language and it stands for Visual Basic for Applications. Let’s see how to set up our VBA Macro and how to add comments in a VBA in Excel.
VBA Macro
Excel is a very advanced tool that contains thousands of functionalities, but VBA Macro comes into existence when we have to do a repeated task. The complex repeated tasks can be automated with the help of VBA Macro.
Initial Set-Up
Go to Developer Tab. We will see that by default developer tab is not present in the menu bar.

Follow the steps:
Step 1: Right-click on any tab in the menu bar. Click on Customize the Ribbon. A dialogue box appears.

Step 2: In the Mains Tab, check the box Developer and click on Ok.

Step 3: Now the Developer Tab is visible.

Step 4: Go to Developer Tab and click on Visual Basic.

Step 5: Now, the VBA tab is opened. Click on Tools in the menu bar and then click on Macros. A dialogue box is open.

Step 6: Write the macro name and click on create.


A Macro is created.
VBA Comments
Comments are the lines in the code that are ignored while executing the code. These are represented as green text in the code. The comments help describe the written code. Knowing the correct use of comments is very important because while working with long and complex code, comments help us identify which part of code does what. It is very helpful for development purposes.
Adding Single Line comment in VBA
Step 1: Click on the line where you want to insert a comment.

Step 2: Type an Apostrophe( ‘ ) at the start of a line.

Step 3: Write the comment you want.

Step 4: Press Enter and you fill find the comment written to be green.

Adding Multi-Line comment in VBA
We can add comments in multiple lines. We use multi-line comments when we have to add points in our description or the description is long.
Step 1: Keep your cursor on the Tool Bar.

Step 2: Right-click on the Tool Bar and click on edit. An extended Tool Bar appears. Drag and place it in the already existing Tool Bar.


Step 3: Select the text you want to comment on and click on Comment Block.

The entire selected text got commented.

Using Buttons to add a comment
Step 1: Go to Toolbar and right-click on it. A menu appears.

Step 2: Click on Customize and a dialogue box appears.

Step 3: Go to edit in the left-side scrollable list.

Step 4: Find Comment Block and Uncomment Block in the right-side scrollable list.

Step 5: Click on Comment Block and drag it to the menu bar. It will look like a button in the menu bar.

Step 6: Click on Uncomment Block and drag it to the menu bar. It will look like a button in the menu bar.

Step 7: With the dialogue box opened. Go to the comment block and right-click on it. A menu appears.

Step 8: Click inside the Name and add a character & at the starting of Comment Block. Then click somewhere outside the appeared menu.

Step 9: Again, right-click on the Comment Block and select Image and Text.

Step 10: Repeat steps 7, 8, 9 for Uncomment Block i.e. right-click on the Uncomment Block and add & in the Name. Also, select the Image and Text in the appeared menu. At last, close the dialogue box.


Step 11: A shortcut for comment and uncomment has been created in the VBA code editor. To comment on a line the shortcut is Alt + C and to uncomment a line the shortcut is Alt + U. You can also use the Comment Block and Uncomment Block buttons to comment on a line. Enter the text you want to comment on.

Step 12: To comment on the written line. You can click Alt + C.

Step 13: To uncomment a line, you can press Alt + U.

Use Rem to Comment
At the start of the comment use the keyword Rem to comment on a line.

Formatting Comments
Step 1: Go to Tools Tab, and right-click on it.

Step 2: A menu appears, and click on Options… A dialogue box appears.

Step 3: Go to Editor Format.

Step 4: Select the Comment Text from the left scrollable list.

Step 5: You can change the color of the comment by selecting Foreground. For example, red. Click Ok.

Step 6: Now, all comments will have a font color of red.

Similar Reads
How to Insert and Run VBA Code in Excel?
In Excel VBA stands for (Visual Basic for Application Code) where we can automate our task with help of codes and codes that will manipulate(like inserting, creating, or deleting a row, column, or graph) the data in a worksheet or workbook. With the help of VBA, we can also automate the task in exce
2 min read
How to Delete a Module in Excel VBA?
Have you ever seen a text file in a notepad or a source code file in visual studio code? These all are just basic files where you can write some code or information. Similarly, we have modules in excel, each module has its code window, where you can write some code and allow it to automate your repe
3 min read
How to Concatenate with a Line Break in Excel?
Excel is a powerful tool to store, manage, and visualize large amounts of data. This tool is usually used by accounting professionals for the analysis of financial data but can be used by anyone to manage large data. Data is entered into the rows and columns. And then, various formulas and functions
3 min read
How to Run Code from a Module in Excel VBA
VBA Macro is for developers. In Excel, the macro is a piece of code written in VBA and VBA is Microsoft's programming language, it stands for Visual Basic for Applications. The module is a file with a .bcf extension that stores the code written in the Visual Basic for Applications editor. Let's lear
4 min read
How to Convert VBA Collections to Array in Excel?
An object that can store a number of values whether it can be of string data type or integer which can be easily manipulated or iterated is called Collection. On the other hand, Array is also used to store the data but it is multidimensional but collections are single dimensions. Now, we will see ho
1 min read
How to Round With Doubles in Excel VBA
The round function is used to round the floating numbers to a particular decimal value. Rounding a number, where it has a long decimal value will give a good balance between accuracy and readability. It also helps in calculation and also to get a precise result. In real life, it is useful in doing m
5 min read
How to Automate Data Entry In Excel?
This instructional exercise will show how to robotize information passages in Excel. While managing vast information, it could be almost difficult to include each datum physically. Thus, automation of information passage might be an answer to this. Our day-to-day work life will be extremely simple o
3 min read
How to Create a Multi-Line Comment in R
In R Programming Language multi-line comments are created using the # symbol at the beginning of each line. These comments are typically used for documentation purposes, helping explain your code's functionality. The R interpreter ignores them during code execution and is useful for providing contex
2 min read
How to Declare and Initialize String Array in Excel VBA?
A string array is an array where we can store only string values in the array, with the help of a string array, we can store more than one string value. We can declare the string array in many ways like declaring a static string array, declaring a variant size array of string using the Array functio
2 min read
How to Embed a PDF in Excel
How to Import a PDF in Excel - Quick Steps Step 1: Go to the Insert menu Step 2: Choose an Object from the menu Step 3: In the Object dialogue box, click on the "Create from File" tab. Step 4: Click Browse to find the file you want to embed. Step 5: Once you've selected the file, click OK Step 6: No
6 min read