Microsoft Office Tutorials and References

In Depth Information

**Logical Operators**

Logical Operators

depending on whether the row matches a set condition. Or you can use the IF()

function to determine what calculation you should perform.

The IF() function has the following function description:

IF(condition, [value_if_true], [value_if_false])

In English, this line of code translates to: If the condition is true, display the second

argument in the cell; if the condition is false, display the third argument.

Consider this formula:

=IF(A1=B2, "These numbers are equal", "These numbers are not equal")

This formula tests if the value in cell A1 equals the value in cell B2. If this is true,

you’ll see the message “These numbers are equal” displayed in the cell. Otherwise,

you’ll see “These numbers are not equal”.

Note:
If you see a quotation mark in a formula, it’s because that formula uses text. You must surround all

literal text values with quotation marks. (Numbers are different: You can enter them directly into a formula.)

People often use the IF() function to prevent Excel from performing a calculation if

some of the data is missing. Consider the following formula:

=A1/A2

This formula causes a divide-by-zero error if A2 contains a 0 value. Excel then

displays an error code in the cell. To prevent this from happening, you can replace this

formula with the conditional formula shown here:

=IF(A2=0, 0, A1/A2)

This formula checks if cell A2 is empty or contains a 0. If so, the condition’s true,

and the formula simply gives you a 0. If it isn’t, then the condition’s false, and Excel

performs the calculation A1/A2.

FreqUently Asked qUestion

Showing and Printing Formulas

How in the world do I print out formulas that appear in

my cells?

Excel gives you a view setting so you can get this record.

Just choose Formulas➝Formula Auditing➝Show

Formulas. Now, Excel displays the cells’ formula contents instead

of the results—but on the current worksheet only. Excel also

widens the columns so they can show more information

(as formulas tend to be longer than their results). Repeat

this process, and then uncheck the setting to return to

normal life.

When you print a worksheet, Excel prints the calculated

value in each cell rather than any formula that happens to

be inside a cell. Usually, that’s what you want to happen.

But in some cases, rather than a printout of the formula’s

results, you want a record of the calculations used to

generate the results.