Unit prices that survive bad data (IFERROR)
The problem
Problem statement
An order's unit price is Total divided by Qty — until someone types 0 as the quantity and every division in the report turns into #DIV/0!. Build the safe version in Unit price cell D2: show the normal price when the math works, and the text "Check qty" when the division blows up.
Guard only the division: a legitimate 0 (case 3) must still come through as 0, not as the fallback text.
Problem data
Show the sheet as a table (selectable, copyable)
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Qty | Total | Unit price |
| 2 | ORD-201 | 4 | 100 |
Notes
#DIV/0! means "you asked me to divide by zero or by an empty cell". IFERROR(value, fallback) returns the fallback only when value produces an error. Note the asymmetry in Case 3: a total of 0 is a perfectly valid number (0 ÷ 5 = 0) — IFERROR leaves it alone. IFERROR catches every error type, so if you only want to trap zero quantities, the IF-check approach is the more surgical tool.
How to approach
Your answer goes in D2. On submit we re-run your formula against 3 different sets of input, so a hardcoded number will fail — the formula has to follow the cells.
- Target cell is D2
- The raw division is C2/B2
IFERRORtakes two arguments: the value to try, then what to show if it errors- Shape:
=IFERROR(?, ?)— the division first, the fallback text second, in double quotes
Official solutions
Show 2 solutions — try it yourself first
Approach 1: IFERROR around the division
=IFERROR(C2/B2, "Check qty")
C2/B2 computes normally when B2 is a real quantity. The moment it returns #DIV/0!, IFERROR substitutes "Check qty" instead of letting the error leak into the report.
Approach 2: check the divisor with IF
=IF(B2=0, "Check qty", C2/B2)
Same result, different philosophy: test the known bad condition before dividing. This never hides unexpected errors — a #REF! or #VALUE! still shows up loudly instead of being swallowed.
Function guide
FAQ
What causes #DIV/0! in Excel?
Dividing by zero or by an empty cell: =C2/B2 errors when B2 is 0 or blank. Fix the data, or wrap the division in =IFERROR(C2/B2, "fallback") to show something useful instead.
How do I hide #DIV/0! errors in a report?
=IFERROR(C2/B2, "") returns an empty-looking cell, or use a real message like "Check qty". A visible message is usually better — silent blanks hide data problems from the people who should fix them.
Is IF(B2=0,…) better than IFERROR?
When zero is the only realistic problem, the IF check is more precise: it converts exactly that case and still surfaces #REF! or #VALUE! loudly. IFERROR converts every error, which is convenient but can mask structural breakage.