Comment A Block In Vba In Excel

Posted on  by 

Comment a block in vba in excel using

Excel completely ignores it when it’s running the VBA code. So you can type whatever you want. We’ll talk about what sort of information you may want to put in comments in a moment. You’ll know that a line has been commented out when the text is green. Open up the Visual Basic Editor in Excel (click the Visual Basic button in the. Excel VBA Tip: Comment Out Blocks of Code (Multiple Lines Quickly). In this video, we go over how to quickly add comments and remove comments from multiple l. How to uncomment a block of codes or lines in VBA which are already commented. In order to un-comment a block of lines at once, follow the below steps: 1. Select the Block which you want to uncomment. Click on the un-comment Block option available as shown in below picture: Uncomment block of comment. For Excel senior user, they always create some VBA codes to solve the complex problems. But, sometimes, they want to protect the VBA code from being viewed or destroyed by others. Just like you can use password to protect workbooks and worksheets, you can also set a password for protecting the macros in Excel. Writing VBA code in Excel has many challenges. Sometimes we test and experiment with large blocks of code. In such cases it would be useful to have an option to comment or uncomment multiple lines at once. Otherwise, if we do it line by line, we can waste a lot of time. This tip can actually save you a lot of time and energy.

VBA Comments in VBE

Comments are used in VBE to document the purpose of the procedures, functions, logic’s, 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.

Comment Block In Vba Excel

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 highlight 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.

Comment A Block In Vba In Excel Function

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

Vba

You can also insert a comment at the end of the statement. Please find below example.

Block

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.

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.

Comment A Block In Vba In Excel Example

UnComment Block : Remove the single quote ( ‘ ) from the beginning of each line in the currently selected statements.

Comment A Block In Vba In Excel Using

Excel VBA Tutorial:

Comment A Block In Vba In Excel Cell

ExampleComment A Block In Vba In Excel

Please click on below link to go back to see Excel VBA Tutorial table of content.

Coments are closed