Sub topic 3
Catching errors with IFERROR
This chapter assumes you can enter and copy formulas, understand relative and absolute references such as $A$2:$B$100, and have used IF and VLOOKUP. It covers how IFERROR works, what it returns, and where it causes trouble. The chapters before it explained the error values. The chapters after it cover IFNA and when to choose each function.
What IFERROR does
IFERROR runs a formula and checks the result. If the result is an error value, IFERROR returns a fallback you supply. If the result is not an error, IFERROR returns it unchanged.
The syntax is:
=IFERROR(value, value_if_error)valueis the formula or expression to evaluate.value_if_erroris what to return ifvalueproduces an error. It can be a number, text, a cell reference, or another formula.
Here is the simplest useful case. Column A holds revenue and column B holds units sold. You want revenue per unit, but some rows have 0 or blank units.
=IFERROR(A2/B2, 0)When B2 is 0, A2/B2 produces #DIV/0!. IFERROR catches it and the cell shows 0. When B2 is 4 and A2 is 100, the cell shows 25.
IFERROR catches all seven standard error values: #DIV/0!, #N/A, #VALUE!, #REF!, #NAME?, #NUM! and #NULL!. It does not distinguish between them. That breadth is both its convenience and its main risk, which later sections cover.
A worked example
Suppose a sales sheet looks like this:
| Row | A: Revenue | B: Units | C: Formula | C: Shown |
|---|---|---|---|---|
| 2 | 100 | 4 | `=IFERROR(A2/B2, 0)` | 25 |
| 3 | 80 | 0 | `=IFERROR(A3/B3, 0)` | 0 |
| 4 | 60 | (blank) | `=IFERROR(A4/B4, 0)` | 0 |
| 5 | 90 | n/a (text) | `=IFERROR(A5/B5, 0)` | 0 |
Row 3 and row 4 fail with #DIV/0!, because Excel treats a blank cell as 0 in arithmetic. Row 5 fails with #VALUE!, because text cannot be divided into a number. All three display 0.
Notice what this shows. Three different problems, a zero divisor, a missing value and a text entry, all look identical in column C. The first two may be legitimate. The third may be a data entry mistake you would want to know about. IFERROR cannot tell you which.
Choosing the replacement value
The second argument decides how the result behaves later. Three choices are common.
Zero
=IFERROR(A2/B2, 0)Zero is a number, so sums, averages and further arithmetic keep working. The cost is that zero looks like a real result. A row with no units shows a per-unit revenue of 0, and an AVERAGE over the column treats it as a genuine observation, which pulls the average down.
Empty string
=IFERROR(A2/B2, "")The cell looks blank, which suits reports. But "" is text, not an empty cell. This has consequences:
SUMandAVERAGEignore text in a range, so totals skip these rows. That is usually what you want.- Direct arithmetic such as
=C2+1or=C2*2fails with#VALUE!, because text cannot be used in arithmetic. ISBLANK(C2)returns FALSE, because the cell contains a formula result.COUNTskips the cell, butCOUNTAcounts it.
A message
=IFERROR(A2/B2, "Check units")A message is the most visible option and works well for a column that people read directly. It has the same text-in-arithmetic problem as the empty string, and it can spread: any formula that references the cell with + or * will fail.
How replacements affect dependent formulas
The following table shows how the same range behaves under each fallback. Assume four rows in C2:C5, where three hold numbers (25, 10, 5) and one failed.
| Fallback | C5 holds | `=SUM(C2:C5)` | `=AVERAGE(C2:C5)` | `=C5+1` |
|---|---|---|---|---|
| `0` | 0 | 40 | 10 | 1 |
| `""` | empty text | 40 | 13.33 | `#VALUE!` |
| `"Check units"` | text | 40 | 13.33 | `#VALUE!` |
The sums are the same, but the averages differ. With 0, the average is 40 / 4 = 10. With text, AVERAGE ignores the failed row and divides 40 by 3, giving 13.33. Neither is wrong in general, but only one matches what you intend. If a missing value means "no data", text is more accurate. If it means "none sold", 0 is more accurate.
Also note that without IFERROR, a single #DIV/0! in the range would make SUM and AVERAGE return #DIV/0! too. Errors propagate through any formula that references them, which is the main reason people reach for IFERROR.
Where to put IFERROR
IFERROR wraps whatever expression you give it, so placement matters.
Around the whole formula
=IFERROR(VLOOKUP(E2, $A$2:$B$100, 2, FALSE) * 1.2, 0)Any error from the lookup or the multiplication is caught. This is convenient but broad.
Around one part
=IFERROR(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), 0) * 1.2Only the lookup is protected. The multiplication stays outside, so a problem there still shows. Wrapping the smallest piece that can fail is a good habit, because it limits how much IFERROR can hide.
Fallbacks that are formulas
The second argument can itself be a calculation:
=IFERROR(A2/B2, A2/AVERAGE($B$2:$B$100))If the division fails, the formula divides A2 by the average units instead. The fallback is evaluated only when needed. If the fallback also errors, the result is that error, since IFERROR has no second safety net.
Wrapping a lookup
IFERROR is often used with VLOOKUP:
=IFERROR(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")This works, but it is the pattern most likely to hide real errors, as the next section shows.
When IFERROR hides real problems
IFERROR treats every error as equal. A formula can fail for a reason that is normal, such as a customer with no orders, or for a reason that means the sheet is broken. The same fallback appears either way.
Consider the lookup above. It should show "Not found" when E2 is missing from A2:A100, which produces #N/A. But it would also show "Not found" in each of these cases:
- You rename a sheet or delete a column used in the formula, producing
#REF!. - You mistype the function name, such as
VLOKUP, producing#NAME?. - You set the column index to 3 in a two-column range, producing
#REF!. - A lookup value has a stray trailing space, so every row appears missing.
In each case the column fills with "Not found" and nothing signals that the formula is broken. A reader assumes the data is missing. This is called masking, and it is the most common way IFERROR causes trouble in practice.
A quick test for masking
Before relying on an IFERROR formula, temporarily remove the wrapper or change the fallback to something loud, such as "ERR". If cells you expected to be fine show the fallback, the handler was hiding something.
A more systematic check counts how often the fallback fires:
=COUNTIF(C2:C100, "Not found")An unexpectedly high count is a signal to investigate.
Narrower alternatives
If you know which error you expect, handle only that one.
For division, test the divisor directly. Only the zero case is handled and every other error stays visible:
=IF(B2=0, "", A2/B2)If B2 contains text, B2=0 is FALSE, so the division runs and returns #VALUE!, which you will see. That is the desired behavior. Note one trade-off: this formula guards only one cause, so it is more work to write when several things can fail.
For lookups, the next chapter introduces IFNA, which catches only #N/A:
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")A #REF! or #NAME? still shows, which is what you want.
Common mistakes
- Using IFERROR everywhere by default. It becomes a habit applied to formulas that never needed it. Use it where you can name the error you expect and the fallback makes sense.
- Forgetting that
""is text. Downstream arithmetic fails with#VALUE!. UseSUMor test withISNUMBERinstead of direct addition. - Using 0 when 0 is meaningful. A missing price shown as 0 can be mistaken for a free item.
- Wrapping the whole formula. Wrap the smallest part that can fail.
- Leaving an error in the fallback. The second argument is not protected. If it errors, the cell shows that error.
- Hiding errors in a final report without checking first. Review the raw errors, fix the causes you can, and only then add handlers for the ones that are expected.
Edge cases
- Arrays. In Excel versions with dynamic arrays, IFERROR works on each element.
=IFERROR(A2:A10/B2:B10, 0)returns an array in which only the failing elements are replaced. - Empty second argument.
=IFERROR(A2/B2, )is valid and returns 0, because the omitted argument is treated as 0. Writing0explicitly is clearer. - Errors you want to keep. If a downstream process, such as a check cell, depends on seeing errors, handle them there rather than at the source.
- Performance. IFERROR evaluates its first argument once, so wrapping a formula does not double the calculation. Patterns like
=IF(ISERROR(x), 0, x)do evaluatextwice, which can slow large workbooks with heavy lookups. This is one reason IFERROR is preferred over that older pattern.
Exercise
A column shows =IFERROR(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), 0). After someone deletes column B from the sheet, every row shows 0 and no error appears. What went wrong, and how would you change the formula so the problem is visible next time?
Show answer
Deleting column B made the lookup range invalid, so VLOOKUP returns #REF! in every row. IFERROR catches all errors, so it replaced #REF! with 0, hiding the damage. Use =IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), 0) so only a missing value (#N/A) becomes 0 and #REF! stays visible. Better still, use a fallback that cannot be mistaken for data, such as "Not found".
Exercise
C2:C5 contains 25, 10, 5 and a cell that returned "" from =IFERROR(A5/B5, ""). What do =SUM(C2:C5), =AVERAGE(C2:C5) and =C5+1 return?
Show answer
SUM returns 40 and AVERAGE returns 13.33 (40 divided by 3), because both ignore text. =C5+1 returns #VALUE!, because "" is text and cannot be used in arithmetic.
Exercise
Rewrite =IFERROR(A2/B2, 0) so that a zero divisor gives 0 but a text entry in B2 still shows #VALUE!.
Show answer
=IF(B2=0, 0, A2/B2). When B2 is text, B2=0 is FALSE, so the division runs and returns #VALUE!.