The VBA Editor - Comments
- 02:14
Understand how to add text notes to code
Downloads
No associated resources to download.
Glossary
VBA CommentsTranscript
Sometimes it can be useful to add textual notes to your code. And these are called comments. When you finish typing them in the code window, by default they appear in green. So you can see here, EnterMyName2 macro, the title macro, there's a comment in here, just here. Okay? And we know it's a comment because it's green. So to type them in, all you need to do is get your cursor onto a blank line of the code window, type in a single quote, apostrophe. Usually you hit the space bar after that and then type in any text you'd like.
When you move your cursor away from that line, the VBA editor will do some evaluating of that line of code, work out that it's a comment and turn the text green.
So you can add text or comments at the beginning or at the end of your macro or even on the particular line of code to remind yourself what this particular line of code does.
So all of these ways to comment your code and add notes to remind yourself about particular things this macro does. You can also comment multiple lines of text or code by using the edit toolbar. If you don't see the edit toolbar, this one up the top here on your code window, then just right click over any existing toolbar and turn on the edit one here. You can see mine's ticked on already. Once you've got the edit window, these two buttons here, comment block and uncomment block, allow you to comment out or uncomment out multiple lines of text. So for example, if I wanted to take the comment markers away from all these lines, then I could use the uncomment block. If I wanted to put them all back again, I could use the comment block. So this is a way to make multiple lines of text comments.