Controlling Your VBA Code
One of the advantages of writing your own VBA procedures instead of simply recording them is that
you end up with much more control over what your code does and how it performs its tasks.
In particular,
you can create procedures that make decisions based on certain conditions and that can perform
loops-the running of several statements repeatedly.
The statements that handle this kind of
processing-control structures-are the subject of this tutorial.
In this tutorial:
- Code That Makes Decisions
- Using If...Then to Make True/False Decisions
- Using If Then Else to Handle a False Result
- Making Multiple Decisions
- Using the Select Case Statement
- Functions That Make Decisions
- Code That Loops
- Using Do..Loop Structures
- Using For...Next Loops
- Using For Each...Next Loops
- Using Exit For or Exit Do to Exit a Loop
- Indenting for Readability