Microsoft Office Tutorials and References

In Depth Information

**AND**

And

The
AND
logical operator performs a conjunction by comparing two expressions. The result of the

AND
operation is True only if both conditions are True. If either or both conditions are False, the
And

operation will evaluate to False.

For example, say you enter the number 500 in cell A1, and you enter the number 850 in cell B1. The

following statement with the
AND
operator will evaluate to True, because both conditions are true at

the same time:

Range(“A1”).Value > 300 AND Range(“B1”).Value > 700

Keeping the same numbers in cells A1:B1, the following statement would evaluate to False, because

even though the first condition is True, the second condition is False:

Range(“A1”).Value > 300 AND Range(“B1”).Value >900

This next statement would also evaluate to False, because even though the second condition is True,

the first condition is False:

Range(“A1”).Value >620 AND Range(“B1”).Value > 700

The final possibility is if both conditions are False, with this statement for example, which would

evaluate to False:

Range(“A1”).Value <200 AND Range(“B1”).Value < 700

Table 8-1 summarizes each possible result of the
AND
logical operator more succinctly.

TABlE 8-1:
Truth Table for the AND Logical Operator

ExprEssion 1

ExprEssion 2

logicAl rEsulT

True

True

True

True

False

False

False

True

False

False

False

False

or

The
OR
operator performs a logical disjunction, whereby if either condition is True, or if both conditions

are True, the result is True. If both conditions are False, the
OR
operation will result in False. For

example, using the same cell values as the previous
AND
example, with 500 in cell A1 and 850 in cell B1, you

can see how differently the four statements will evaluate, using
OR
instead of
AND
as the logical operator.

The first statement will evaluate to True, not necessarily because both conditions are True, but

because at least one condition is True:

Range(“A1”).Value > 300 OR Range(“B1”).Value > 700