Code That Makes Decisions
A smart procedure performs tests on its environment and then decides what to do next based on the results of each test. For example, suppose you've written a Function procedure that uses one of its arguments as a divisor in a formula. You should test the argument before using it in the formula to make sure that it isn't 0 (to avoid producing a "Division by zero" error). If it is, you could then display a message that alerts the user of the illegal argument. Similarly, a well-designed application will interact with the user and ask for feedback in the form of extra information or a confirmation of a requested action. The program can then take this feedback and redirect itself accordingly.
In this tutorial:
- Controlling Your VBA Code
- 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