Using Subroutines in Macros

Suppose you’re creating a complex macro and you discover that, among other things, you want the macro to perform a task you’ve already recorded under a different name. Or suppose you discover that a task you’ve recorded as part of a macro is something you’d like to use by itself—or in an entirely different macro. In our CompanyAddress macro, for example, it might be convenient if we could quickly and easily apply the font formats of the company name to other items in a worksheet.

With VBA, you can divide large macros into a series of smaller macros, and you can easily string together a series of small macros to create one large macro. A macro procedure that is used by another macro is called a subroutine. Subroutines ...

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