Excel VBA Tips: How to comment or uncomment a Block of Code in VBA
Providing proper short descriptions for each of your functions or statements etc. makes your VBA code – easy to read, easy to understand by anyone who refers your code.
Now the question is, how can you write description in English language in between your VBA code? VBA compiler will start giving compile error. It is very simple by commenting those lines which you do not want get executed.
How to comment a line in VBA code
In VBA to comment a particular line which you do not want to get compiled or executed, you can type your line followed by single quote ( ‘ ). The complete line which is starting with single quote is ignored and does not get executed. All the commented lines get formatted in green color as shown below image.
It means to comment a block of code or lines you need to put single quote for each lines. It becomes difficult if you have got a function of hundreds of lines of code which you want to comment. then how to comment them all in simple way??
How to comment a block of codes or lines in VBA
In order to comment a block of lines at once, follow the below steps:
1. Select the Block which you want to comment
2. Click on comment Block option available as shown in below picture:
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
2. Click on the un-comment Block option available as shown in below picture:
Where to find this comment Block Option in VBA window
Follow the below steps to enable or see this comment block option in VBA window:
1. To make this option visible follow : View –> Toolbars –> Click on Edit
My name is Vishwamitra Mishra. Friends Call me Vishwa. This blog is authored by me. I am an Excel Geek. Well, this blog talks a lot about my passion in Excels & Macros so I’ll not talk about it :) I am very much passionate about traveling & quite recently discovered that I am a good photographer too..:P
AND GET A FREE!
E-BOOK FOR EXCEL VBA BEGINNERS
DON'T MISS ANY NEW ARTICLE !
Get your FREE! E-Book & Have Every New Article Delivered Straight To Your Email-Box