Decision Making with VBA

You can make decisions in your VBA procedures by using conditional expressions inside the special control structures. A conditional expression is an expression that uses a relational operator (see Table 5-1), a logical operator (see Table 5-2), or a combination of both. When Visual Basic encounters a conditional expression in your program, it evaluates the expression to determine whether it is true or false.

Table 5-1: Relational operators in VBA

Operator

Description

=

Equal to

<>

Not equal to

>

Greater than

<

Less than

> =

Greater than or equal to

<=

Less than or equal to

Table 5-2: Logical operators in VBA

Operator

Description

AND

All conditions must be true before an action can be taken.

OR

At least one of the conditions must be true before an action can be taken.

NOT

If a condition is true, NOT makes it false. If a condition is false, NOT makes it true.

0 0

Post a comment