VBA Comments in Visual Basic Editor

VBA Comments in VBE

Comments are used in VBE to document the purpose of the procedures, functions, logics, and variables. It helps other programmers can effortlessly work on the same code in future. Comments are ignored by the interpreter and compiler and does not affect performance while execution. It is good programming practice or habit to begin all procedures or functions with a comment describing what it does. When you change any existing code details (statements), remember to update comment as well what it does.

You can also add comments to your code by preceding the text with the REM keyword. However, the Single Quote (‘) symbol and the Comment or Uncomment buttons are easier to use. It occupies less space in memory. Commented line always highlighted in green color in the code window.
Note: While debugging lines or statements of code we can comment temporarily. The statements can be Uncommented afterwards. It is one of a useful technique to save processing time.

Here are the two methods to add comments to statements in Excel VBE
Method 1: Any line or statement starts with a Single Quote (‘) is treated as comment in VBA.
Here is the simple example for your reference.
‘Here is simple example to comment code

You can also insert a comment at the end of the statement. Please find below example.
Dim iCnt As Integer ‘Here is another example to comment code

Method 2: Any line or statement that starts with the keyword ‘REM’ is treated as comment in VBE.
Here is the simple example for your reference.

REM Here is the simple example to comment code
REM Date: 1st Jan 2018

The Comment Block and UnComment Block buttons on the Edit toolbar are very useful for commenting or uncommenting multiple lines of code in one shot.
Comment Block : Adds the single quote ( ‘ ) to the beginning of each line in the currently selected statements.
UnComment Block : Remove the single quote ( ‘ ) from the beginning of each line in the currently selected statements.