How to comment – Block of multiple lines of code – in Vba?

Comment Block & Uncomment Block

In VBA to comment a multiple lines of code with single step:

There is no keyboard short available commenting. But VBA editor has built in menu option to comment any number of lines of code.

By default this option is not enabled. This has to be enabled using this option.

1. Click VBA Menu

2. Choose View -> Toolbars

3. Click Edit.

4. New Icon toolbar will be displayed

Check all the options in the newly displayed toolbar. One of the icon will display tooltip ‘Comment Block’.

Test Commenting block of code using this option

Select few lines of code in your current VBA project. Then click on the option ‘Comment Block’ from this menu toolbar.

Now you can see that VBA editor has commented all the lines of code in current selection.

Similar to commenting, the next option in the toolbar is uncommenting.

This is the reverse of the above option used to uncomment the already commented block of code.