The If statements

Many of the previous examples have shown that programs often have to make decisions. This means that a program will follow one course of action if one comparison is true or perhaps another course of action if it is false. There are two main structures for implementing decisions in VBA: If and Select Case.

If uses the comparison operators you learned earlier in this lesson to test data values, and can test whether to execute complete blocks of code. This means that If lets your program execute only parts of the program if the data warrants partial execution. In this section we will look at three variants of the If statement. These are:

♦ One-way selection using If...Then

♦ Multiway selection using If.Then Elself.Else

0 0

Post a comment