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 spreadsheets with our free VBA Developer's Guide It’s easy to copy and paste a macro like this, but it’s harder make one on your own. To help you make macros like this, we built a free VBA Developer Guide and a bunch of pre-built macros so you can master file I/O, arrays, strings and more.
It’s easy to copy and paste a macro like this, but it’s harder make one on your own. To help you make macros like this, we built a free VBA Developer Guide and a bunch of pre-built macros so you can master file I/O, arrays, strings and more.
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.