Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Controlling Code Execution
Some VBA procedures start at the top and progress line by line to the bottom. Macros that you record, for example, always work in this fashion. Often, however, you need to control the flow of your routines by skipping over some statements, executing some statements multiple times, and testing conditions to determine what the routine does next.
The preceding section describes the For Each-Next construct, which is a type of loop. This section discusses the additional ways of controlling the execution of your VBA procedures:
• GoTo statements
• If-Then constructs
• Select Case constructs
• For-Next loops
• Do While loops
• Do Until loops
GoTo statements
The most straightforward way to change the flow of a program is to use a