• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 30. Taking Control of Excel with... > Creating Subroutines and Functions

Creating Subroutines and Functions

As your macros grow in number, length and complexity you will probably find that you create the same code over and over again. If you do, you are ready to create a subroutine. Of course, every macro you have created is already a subroutine, but you've probably just run each macro, or sub procedure, on its own. In this section, you'll see how to create and call sub procedures from your macros. You'll also learn how to create your own functions, to perform calculations in your macros, as well as in an Excel 97 workbook.

Reusing Code with Subroutines

A subroutine is nothing more than a VBA sub procedure that you call from another procedure or macro. To be a little more formal about it, a sub procedure is a named collection of VBA statements, which can be executed as a unit. The formal syntax for a sub procedure is as follows:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint