BLOGS BY TOPIC▼
BLOGS BY AUTHOR▼
BLOGS BY YEAR▼
Commenting code is an art form! This series of blogs explains why, how and when to comment in VBA.
- Why Write Comments in Excel Visual Basic
- Adding Comments in VBA macros for Excel
- Commenting Out Code in Excel Visual Basic (this blog)
Posted by Andy Brown on 28 April 2011
You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Commenting Out Code
Rather than have to type an apostrophe before every line of code, you can select a block of code and comment it out:
|Select the code to comment out ...||... to tell VBA to ignore it|
To do this, you first need to display the correct toolbar.
Displaying the Correct Toolbar
The easiest way by far to comment out code is using the Edit toolbar:
Right-click on any toolbar in VBA and tick the Edit toolbar to display it
Once you have this visible, you can comment code out as shown below.
Commenting Out (and Back In)
To comment out code, first select part or all of the lines of code you want to comment out:
You don't have to select all of each line (here we'll comment out the 3 lines of code wholly or partially selected).
You can then comment the lines out:
Click on the tool shown to comment out selected lines (or the one to its right to comment them back in)
Commenting out code is particularly useful for lines copied from the Internet.