Documenting Macros and Custom Functions

Even simple macros and custom functions can be difficult to read. You can make them easier to understand by typing explanatory text in the form of comments. You add comments by preceding the explanatory text with an apostrophe. For example, Figure 28-4 shows the DISCOUNT function with comments. Adding comments like these makes it easier for you or others to maintain your VBA code as time passes. If you need to make a change to the code in the future, you’ll have an easier time understanding what you (or someone else) did originally.

The DISCOUNT custom function now includes comments.

Figure 28-4. The DISCOUNT custom function now includes comments.

An apostrophe ...

Get Microsoft® Excel® 2010 Inside Out now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.