How to Comment a Block of Lines in VBA
This is one of the most common questions developers starting their journey to learning VBA ask. In VBA, how do I comment a block of lines at once? Comment blocks are a fundamental feature of any programming language, but it’s not enabled by default in VBA.
To enable VBA comment blocks, you have to configure your Visual Basic Editor (VBE).
Enabling the VBA Edit Toolbar
- Open your Visual Basic Editor (Alt+F11)
- Click View
- Click Toolbars
- Check the box beside Edit.
Navigating the Edit Toolbar
Once you enable the Edit Toolbar, new buttons for Comment Block and Uncomment Block will appear.
You can drag this toolbar wherever you want in your VBE. I like mine docked beside my Debug Toolbar.
Commenting Blocks of Lines
Once you’ve made it this far, you can comment blocks of VBA code by highlighting the lines and selecting the “Comment Block” button. It’ll look something like this:
Make powerful macros with our free VBA Developer's Kit
There's a lot to unpack here. To save time and become really good at VBA, make sure you get our free VBA Developer's Kit below. It's full of shortcuts, tips and pre-built macros to make writing VBA easier.
Commenting blocks of code in VBA is a necessary skill for building and debugging your macros. In this VBA tutorial I showed you how to enable one of the most important toolbars you can have in VBA. I’m still shocked that this toolbar isn’t visible by default, but that’s okay. Now it is!
That’s all for this tutorial. When you’re ready to take your VBA to the next level, subscribe using the form below.