Chapter 3. Introducing Visual Basic for Applications

Create Sub Procedures

A block of VBA code that performs a task is a procedure. A Sub procedure is a special type of procedure that performs a task but does not return a value. Every time you record a macro, Excel creates a Sub procedure. You can view the Sub procedures in the VBE. You can also use the VBE to create Sub procedures.

Every Sub procedure begins with the keyword Sub followed by the name of the Sub procedure and parentheses. If the Sub procedure does not take any arguments, the parentheses are empty. If the Sub procedure does take arguments, you place the arguments between the parentheses, separated by commas. Sub procedures end with the keywords End Sub.

Every Sub procedure must have ...

Get Excel® Programming: Your visual blueprint™ for creating interactive spreadsheets 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.