Commenting a block of code in VBA

One way is to manually place an apostrophe at the start of every line in the block.

A much easier way (I just found out today) is:

  • Go to View-Toolbars-Customise
  • Select the Command tab
  • Select the Edit Category on the left
  • Drag the “Comment Block” and “Uncomment Block” icons onto your toolbar.

Now you can comment (or uncomment) as many lines as you like with a single click.

About these ads
This entry was posted in Excel, VBA and tagged , , . Bookmark the permalink.

5 Responses to Commenting a block of code in VBA

  1. Colin Legg says:

    The comment block buttons are a great tip, Doug.

    In my own set-up I’ve gone a step further and have hotkeys for commenting / uncommenting code blocks. One could code this oneself, but I’m a big fan of MZ-Tools which lets you set up hotkeys under Tools > MZ-Tools > Options > Shortcuts. For comment block I use CTRL+K and for uncomment block I use CTRL+U, to partially match the shortcuts in Visual Studio.

    Like

  2. Fábio says:

    Just write click on the toolbar and set Edit

    Liked by 1 person

  3. dougaj4 says:

    Colin – Thanks, I’ll have a look (I’m already an MZ-Tools user).

    Fabio – yes that will work as well.

    Like

  4. Rosss says:

    wow, you just found this out to day!!! its amazing what we miss. Hope your good mate.
    Ross

    Like

    • dougaj4 says:

      Hi Ross, there are probably quite a few basic things like that I don’t know.

      I blame too many years spent persevering with Lotus 123 :)

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s