Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
When you record or write an Excel macro, it's a good idea to put some information about the macro and what it's supposed to do in the code module where the macro was stored. You can do that by adding a comment. I'm going to work with the sample file called Comments. So I'll double-click. I do want to work with macros in this file - I'm expecting them, so I will click Enable macros. I now need to display the Developer tab of the Ribbon, so that I can use my Macro tools. Now that I'm here, I can click the Macros button.
Then in the Macro dialog box, I can click the macro that I want to work with, that I want to add a comment to. That will be Absolute. So I'll make sure it is selected here in the Macros pane. Then I will click Edit. When you open up a macro, you'll see several different kinds of text. In blue, for example, here with Sub, that is a structural note. In other words, it's about the structure of the routine. This is the start of the routine with Sub, End Sub is the end of the routine, and so on. The black text are the actual instructions that Excel will be implementing as part of the code.
There is a third type of text, and you can see it here down at the bottom, and that is what's called a comment. A comment allows you to provide information about your code. It doesn't run. It's just there to make the code more understandable by humans. If you want to add a comment to a macro, you can go to a blank line, type a single quotation mark, very important that it be a single quotation, and then type in your comment text. So, for example, I could say 'Uses absolute references.' When I move off the line, either by pressing the down arrow or by pressing the Return key, Excel highlights the text in green.
That way you know it's a comment. If you want, you can also add a comment to an existing line of code, again, by going down beside the code, and in this step, we changed the size of the text in the cell. Press a Space. Make sure there is at least one space between the code and the comment, and then type a single quote, and you can then say, 'This is the change.' When you press the down arrow, Excel highlights the remainder of the line in green, indicating that it contains a comment.
This code will still run, but this comment is here in case anyone wants to read it to understand what was changed inside this macro. As soon as you type a single quote, everything else on the line is considered a comment. So in other words, you couldn't put additional code out here by typing some other character. Once Excel sees the single quote, everything else on the line is considered a comment. Comments are one of the most valuable programming tools at your disposal. Knowing the programmer's intentions when they recorded or wrote a macro goes a long way toward helping you figure out how it works.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 70056 Viewers
80 Video lessons · 127442 Viewers
52 Video lessons · 62374 Viewers
59 Video lessons · 48085 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.