VBA Comments. Comments are lines of code skipped over when the code is run. In the coding, these are shown as green text. Descriptions of the code are provided in the comments. A comment is any remark in the VBA code after an apostrophe. Knowing the proper usage of comments is crucial when working with large and complex code. Comments assist us in understanding which section of the code accomplishes what. It is beneficial for the sake of progress.
1. Adding Single Line Comment in VBA
You can add comments to individual lines of code in several methods, including single quotation marks (‘), the comment block button on the ToolbarToolbar, or the Rem keyword. The quickest approach to comment on a line in the programme is to place a single quotation mark at the beginning of the line.
Step 1: Select the line where you want to insert a comment.
Step 2: Enter an apostrophe at the beginning of each line.
Step 3: Write the comment you want.
Step 4: Click Enter. The entered comment will turn green.
See More: VBA Constant
2. Adding Multi-Line Comment in VBA
Multi-line comments are helpful when we need to elaborate on our description or the description itself is lengthy.
Step 1: Make sure your cursor is on the Tool Bar.
Step 2: Right-click on the Tool Bar and then on edit. A more comprehensive Toolbar will show up. Drop it into your Tool Bar or drag it there.
Step 3: Choose the text you want to comment on and tap on Comment Block.
3. Using Buttons to add a Comment
Step 1: Visit ToolbarToolbar and right-click on it to appear a menu.
Step 2: Click on Customize to bring up a dialogue box.
Step 3: Go to edit in the left-side scrollable list.
Step 4: Scroll down the list on the right to find Comment Block and Uncomment Block.
Step 5: Click on Comment Block and move it to the menu bar. It will simulate a menu button in appearance.
Step 6: Select Uncomment Block and add it to your ToolbarToolbar by clicking and dragging it there. It’ll have the appearance of a menu button.
Step 7: Open a discussion box and right-click the comment box.
Step 8: Click in the Name box and add to the beginning of the Comment Block. Next, click outside the newly-appeared menu.
Step 9: Right-click on the Comment Block and choose Image and Text.
Step 10: Follow steps 7–9 again for the Uncomment Block, this time by right-clicking on it and entering “&” in the Name field. In the drop-down menu that appears, choose both the Image and the Text options.
Step 11: A shortcut for commenting and uncommenting has been made in the VBA code editor. The keyboard shortcut for commenting a line is Alt + C, while the one for uncommenting it is Atl + U.
Using Rem Keyword
Just type the Rem keyword at the beginning of a line to add a comment to that line. No quotation marks or apostrophes are required.
Sub ToCommentLine() Rem MsgBox "This is the line to comment." End Sub
Here are some rem keyword limitations:
Put at least one space before the Rem keyword at the beginning of your comment. Rem must always be the first word of a line and cannot be used between lines to comment on the entire line.
out. I like what I see so now i am following you.