Sub topic 2
Fixing #DIV/0!: dividing by zero or an empty cell
This chapter assumes you can enter formulas, use cell references such as A2 and B2, and use basic functions such as AVERAGE. It covers why Excel returns #DIV/0!, how to find the cause, and how to fix it without hiding real problems.
What #DIV/0! means
Excel shows #DIV/0! when a formula divides by zero. The divisor is the number you divide by. In =A2/B2, the divisor is B2.
Excel treats two situations as a zero divisor:
- B2 contains the number 0.
- B2 is empty. Excel reads an empty cell as 0 in arithmetic.
Some functions divide internally, so you can get the error without typing a /. AVERAGE divides the sum by the count of numbers. If the range has no numbers, the count is zero and the function returns #DIV/0!. Functions such as MOD and QUOTIENT can also return it.
The error also spreads. If C2 holds #DIV/0! and D2 is =C2*2, then D2 shows #DIV/0! too. Fix the first cell in the chain, not the later ones.
A worked example
Suppose you track the share of a sales target that each person reached.
| Row | A | B | C |
|---|---|---|---|
| 1 | Sales | Target | Percent of target |
| 2 | 450 | 500 | 90% |
| 3 | 300 | 0 | #DIV/0! |
| 4 | 120 | (empty) | #DIV/0! |
Column C contains =A2/B2, filled down. Rows 3 and 4 fail because their divisors are 0 and empty.
Step 1: Check the divisor
Before you change the formula, ask why the divisor is zero or empty. There are two common answers:
- The data is incomplete. The target has not been entered yet.
- A zero is a valid value, and the result is undefined for that row.
In the first case, the best fix is to enter the missing data. In the second case, the formula should handle the zero on purpose.
To find the cause, select the cell and look at the formula bar. Click into B3 and B4 to see what they contain. A cell that looks blank may hold a space or an empty-string result from another formula. That is a different problem from a truly empty cell, and it usually produces #VALUE! instead.
Step 2: Test the divisor with IF
When a zero divisor is expected, test it before dividing:
=IF(B2=0,"",A2/B2)If B2 is 0 or empty, the formula returns an empty string, which looks blank. Otherwise it divides normally. The test happens first, so the division never runs on a bad divisor.
You can return a word instead of a blank:
=IF(B2=0,"No target",A2/B2)Pick a label that tells the reader what is missing. A blank cell can look like a forgotten formula.
Step 3: Handle AVERAGE on an empty range
For AVERAGE, the zero divisor is the count of numbers, so you cannot test a single cell. Wrap the formula in IFERROR:
=IFERROR(AVERAGE(B2:B10),"No data")AVERAGE returns #DIV/0! only when the range holds no numbers, and IFERROR replaces that result with the text. Text cells and empty cells in the range are ignored, so a range of only text also triggers the message.
Common mistakes
- Fixing the symptom downstream. Changing D2 does nothing if the error starts in C2. Use the cell where the error first appears.
- Testing the wrong cell.
=IF(A2=0,"",A2/B2)checks the dividend, not the divisor, so a zero in B2 still fails. - Assuming a blank-looking cell is empty. A cell holding a space or
""is text. Use=ISBLANK(B2)to check for a truly empty cell. - Hiding zeros that matter. Returning "" for every zero divisor can hide data-entry mistakes. Decide whether a zero should be reported instead of hidden.
Exercise
Column C holds =A2/B2 and shows #DIV/0! in rows 3 and 4. B3 contains 0 and B4 is empty. Write a formula for C2 that shows "No target" when B2 is 0 or empty, then explain why the same formula works for both rows.
Show answer
Use =IF(B2=0,"No target",A2/B2) and fill it down. Excel treats an empty cell as 0 in a comparison with 0, so B2=0 is true for both the cell holding 0 and the empty cell. The division runs only when the divisor is non-zero.
Exercise
A cell contains =AVERAGE(B2:B10) and shows #DIV/0! because B2:B10 holds only text. Which formula shows "No data" in this case, and what risk does it carry?
Show answer
=IFERROR(AVERAGE(B2:B10),"No data"). The risk is that IFERROR also hides unrelated errors such as #REF! in the range, so a real mistake could appear as "No data".