Part II: Working with Formulas and Functions
10 − 0 = 10
10 − 0 = 10
10 − 0 = 10
10 − 0 = 10
...infinity
Mathematicians call the result you get when dividing any number by zero undefined.
Software like Excel simply gives you an error when you try to divide by zero. In Excel, when
you divide a number by zero, you get the #DIV/0! error.
You can avoid this by telling Excel to skip the calculation if your denominator is a zero.
Figure 10.9 illustrates how to do this by wrapping the division operation in Excel’s IF
function.
=IF(C4=0, 0, D4/C4)
FIGURE 10.9
Using the IF function to avoid a division-by-zero error
The IF function has three arguments: the condition, what to do if the condition is true,
and what to do if the condition is false.
The condition argument in this example is that the budget in C4 is equal to zero (C4=0).
Condition arguments must be structured to return TRUE or FALSE, which usually means
there is a comparison operation (such as an equal sign or greater-than sign) or another
worksheet function that returns TRUE of FALSE (like ISERR or ISBLANK).
If our condition argument returns TRUE, the second argument of the IF function is
returned to the cell. Our second argument is 0 , meaning that we simply want a zero dis-
played if the budget number in cell C4 is a zero.
If the condition argument is not zero, the third argument takes effect. In our third argu-
ment, we tell Excel to perform the division calculation (D4/C4).
So, this formula basically says if C4 equals 0, then return a 0; otherwise, return the result
of D4/C4.