Microsoft Office Tutorials and References
In Depth Information
The following statement would evaluate to True, on the strength of the first condition being True,
even though the second condition is False:
Range(“A1”).Value > 300 OR Range(“B1”).Value >900
This next statement would also evaluate to True because, despite the first condition being False, the
second condition is True:
Range(“A1”).Value >620 OR Range(“B1”).Value > 700
The final possibility is if both conditions are False, meaning that in this case, because neither
condition is True, the statement would evaluate to False:
Range(“A1”).Value <200 OR Range(“B1”).Value < 700
Table 8-2 summarizes each possible result of the OR logical operator.
TABlE 8-2: Truth Table for the OR Logical Operator
ExprEssion 1
ExprEssion 2
logicAl rEsulT
Careful! Comparing logical expressions does not mean you can compare the
impossible. Consider the following example:
Dim intNumber As Integer
intNumber = 0
MsgBox intNumber <= 5 Or 10 / intNumber > 5
Because it is impossible to divide a number by zero, this code will produce an
error even though the first condition evaluated to True.
The NOT operator performs logical negation. Similar to the negative sign in front of a worksheet
formula, the NOT operator will invert an expression’s True or False evaluation. For example, this line of
code will toggle as on or off the display of gridlines on the active worksheet:
ActiveWindow.DisplayGridlines = Not ActiveWindow.DisplayGridlines
The logic behind this use of the NOT operator is to make the status of an object’s property be opposite
of whatever its current status is. In this case, the DisplayGridlines property of the ActiveWindow
object can only be True (show the gridlines) or False (do not show the gridlines). Therefore, using the
Search JabSto ::

Custom Search