Procedures
Procedures are named blocks of code that perform a task. I’ve shown a lot of procedures already and I feel a little bad about waiting this long to define that term. Procedures can have arguments
, which let you pass values in to the procedure from somewhere, and they may return values
through their name. Figure 2-5 illustrates these parts using the CubeRoot example from Chapter 1.
Visual Basic has four kinds of procedures:
-
Subprocedures Perform a task but don’t have return values.
-
Functionprocedures Perform a task and return a value as their result.

Figure 2-5. Parts of a procedure
-
Propertyprocedures Get or set a value in an object or module.
-
Eventprocedures A special kind of
Subprocedure that respond to events that occur in Excel. Only classes can contain event procedures.
The following sections explain these different types of procedures and how you use them.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access