Documenting Macros and Custom Functions

Even simple macros and custom functions can be difficult to read. You can make them easier to understand by entering explanatory text in the form of comments. You add comments by preceding the explanatory text with an apostrophe. For example, Figure 32-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 did originally.

The Discount custom function now includes comments.

Figure 32-4. The Discount custom function now includes comments.

An apostrophe tells Excel to ...

Get Microsoft® Office Excel 2003 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.