Controlling Your VBA Code

Code That Makes Decisions 91

Using If...Then to Make True/False Decisions 92

Using If...Then...Else to Handle a False Result 93

Making Multiple Decisions 94

Functions That Make Decisions 101

Code That Loops 104

Using Do...LoopStructures 105

Using For...Next Loops 106

Using For Each...Next Loops 109

Using Exit For or Exit Do to

Exit a Loop 110

Indenting for Readability 111

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 chapter.

0 0

Post a comment