Sub topic 10
Catching errors with IFERROR
This chapter assumes you can write a basic IF formula, copy it down a column, and read a cell reference such as B2. It builds on the earlier chapters on IF syntax, return values, and nesting. By the end you will know what IFERROR does, where to place it, and when it hides problems you need to see.
Why errors appear in IF formulas
An IF formula can be correct and still fail on some rows. The test or the value you return may contain a calculation, and that calculation can break when the data is unusual. A cell that shows #DIV/0! in the middle of a report looks unfinished. It can also spread, because any formula that refers to that cell inherits the error.
Here is a small grade sheet. Column B holds points earned and column C holds points possible.
| Row | A (Name) | B (Earned) | C (Possible) |
|---|---|---|---|
| 2 | Ana | 40 | 50 |
| 3 | Ben | 20 | 0 |
| 4 | Cleo | absent | 50 |
| 5 | Dev | 30 | 50 |
Suppose you want to label each row "High" when the ratio is above 0.5 and "Low" otherwise.
=IF(B2/C2>0.5, "High", "Low")Row 2 returns "High". Row 3 returns #DIV/0!, because C3 is 0. Row 4 returns #VALUE!, because the text "absent" cannot be divided. Row 5 returns "High". The IF is fine. The division inside its test is what fails.
What IFERROR does
IFERROR checks one value. If that value is an error, it returns a replacement. If not, it returns the value unchanged.
=IFERROR(value, [value_if_error])valueis the formula or reference to evaluate.value_if_erroris what to return whenvalueis an error. It is optional. If you leave it out, Sheets returns an empty cell display (an empty string).
Applied to the grade sheet:
=IFERROR(IF(B2/C2>0.5, "High", "Low"), "Check data")Rows 3 and 4 now show "Check data". Rows 2 and 5 show "High", exactly as before. The IF runs first. IFERROR looks only at what it produced.
The diagram shows the order of evaluation.
Which errors it catches
IFERROR catches every error value a formula can evaluate to. The common ones are:
| Error | Typical cause |
|---|---|
| `#DIV/0!` | Dividing by zero or by an empty cell |
| `#VALUE!` | Text where a number is needed, such as `"absent"/50` |
| `#N/A` | A lookup that finds no match |
| `#REF!` | A reference to a deleted cell or range |
| `#NAME?` | A misspelled function name or an unknown name |
| `#NUM!` | An invalid number, such as the square root of a negative |
One category is not covered. If the formula is malformed, for example with mismatched parentheses, Sheets cannot evaluate it, so there is no value for IFERROR to inspect. You fix those by editing the formula. The troubleshooting chapter covers them.
Placing IFERROR: outside or inside
You can put IFERROR around the whole IF, or around only the risky part. The two positions behave differently.
Outside the IF, one fallback covers every error anywhere in the formula:
=IFERROR(IF(B2/C2>0.5, "High", "Low"), "Check data")Inside the IF, you protect one calculation and let the IF continue:
=IF(IFERROR(B2/C2, 0)>0.5, "High", "Low")Here a failed division becomes 0, which is not greater than 0.5, so those rows return "Low". The formula never shows an error, but it also reports "Low" for missing data. That is a quiet wrong answer. The outer version is safer when "I could not compute this" is a real third outcome.
Choose by asking what the failed row should mean:
- If a failure is its own outcome, such as "Check data", put
IFERRORoutside and return a distinct message. - If a failure has a sensible default, such as a missing bonus counting as 0, put
IFERRORaround only that piece.
Prefer testing the cause when you know it
IFERROR is a catch-all. When you know the one problem you expect, a direct test is more precise:
=IF(C2=0, "Check data", IF(B2/C2>0.5, "High", "Low"))This handles a zero denominator and nothing else. Row 4 ("absent") still returns #VALUE!, and you see it. That is often what you want. The error tells you the data in column B is wrong, which a blanket IFERROR would have hidden.
You can also test for blanks, as in the earlier chapter, and combine tests with OR:
=IF(OR(C2="", C2=0), "Check data", IF(B2/C2>0.5, "High", "Low"))The trade-off is length and effort. Every case you anticipate adds a branch. IFERROR costs one wrapper but gives up the ability to tell causes apart.
IFERROR with lookups
The most frequent use outside IF is handling #N/A from a lookup. Suppose a table in F2:G10 maps names to grades, and you look up the name in A2:
=IFERROR(VLOOKUP(A2, $F$2:$G$10, 2, FALSE), "Not listed")If A2 is not in the table, VLOOKUP returns #N/A and the cell shows "Not listed". You can then feed the result into an IF:
=IF(IFERROR(VLOOKUP(A2, $F$2:$G$10, 2, FALSE), 0)>=50, "Pass", "Fail")Names that are missing from the table count as 0, so they fail. Decide on purpose whether that is the right treatment.
Note the $ signs on the table range. When you copy the formula down, the lookup table must stay fixed, as in the chapter on relative and absolute references.
The narrower option: IFNA
Sheets also has IFNA, which replaces only #N/A:
=IFNA(VLOOKUP(A2, $F$2:$G$10, 2, FALSE), "Not listed")For lookups this is usually the better choice. A missing match is an expected result, but a #REF! caused by a deleted column is a bug, and IFNA lets it show. Use IFERROR when you want to cover all error types, and IFNA when only "no match" is acceptable.
Choosing the fallback value
The second argument can be anything a formula can return. The choice matters because other formulas may read the result.
| Fallback | Result | Good for | Watch out for |
|---|---|---|---|
| `"Check data"` | Visible text | Reports that people read | `SUM` ignores it, but `+` on it causes `#VALUE!` |
| `0` | A real number | Totals and averages | Missing data looks like a true zero and pulls averages down |
| `""` | Empty string | Clean-looking output | The cell is not truly empty. `ISBLANK` returns FALSE for it |
| Omitted | Empty string | Quick cleanup | Hides the problem with no signal at all |
Averages show the difference clearly. AVERAGE ignores text and empty strings but counts zeros. If three rows hold 80, 90, and an error replaced by 0, the average is 56.7. If the error is replaced by "", the average is 85.
=AVERAGE(D2:D4)For numeric columns that feed later calculations, "" or text usually distorts results less than 0 does.
Using IFERROR with ARRAYFORMULA
IFERROR works inside ARRAYFORMULA, and the pairing is common when a whole column of divisions might fail:
=ARRAYFORMULA(IF(A2:A="", "", IFERROR(IF(B2:B/C2:C>0.5, "High", "Low"), "Check data")))The outer IF skips rows where column A is empty, so you do not get a column of "Check data" below your data. The IFERROR then handles only rows that have a name. Put the blank test on the outside. If you put IFERROR outside, every unused row below the data would divide an empty cell by an empty cell, error out, and print the fallback text all the way down the sheet.
Common mistakes with IFERROR
- Wrapping everything by habit. A formula that always shows a clean result can be wrong without anyone noticing. Add
IFERRORafter you have seen which errors occur and decided they are acceptable. - Masking a typo. If you misspell
IFasIFF, the result is#NAME?, andIFERRORturns it into your fallback on every row. The formula looks like it works and never does. Build and check the formula withoutIFERRORfirst, then add the wrapper. - Forgetting the quotes on text.
=IFERROR(B2/C2, Check data)is not a text fallback. Sheets readsCheck dataas unknown names. Write"Check data". - Expecting a blank, but getting
"". The omitted second argument and""both give an empty-looking cell that is not empty. Tests such asA2=""return TRUE for it, butISBLANK(A2)returns FALSE. - Counting on a number, receiving text. A downstream formula such as
=E2*2fails with#VALUE!if E2 holds "Check data". Either use a numeric fallback or make the downstream formula check first.
A worked example
Build the final formula in steps, using the grade sheet.
- Start with the plain formula and watch where it fails:
=IF(B2/C2>0.5, "High", "Low"). Rows 3 and 4 show errors. - Identify the causes. Row 3 has a zero denominator and row 4 has text in B.
- Decide on the meaning. Both rows are bad data, so they should say so rather than "Low".
- Wrap the formula:
=IFERROR(IF(B2/C2>0.5, "High", "Low"), "Check data"). - Copy it down column D. Rows 2 to 5 now show High, Check data, Check data, High.
- Count the problems with
=COUNTIF(D2:D5, "Check data"), which returns 2.
If you want only the zero-denominator case handled and want "absent" to stay visible, use the direct test from earlier and skip IFERROR altogether.
Exercise
Cell C2 sometimes contains 0, and B2 holds a number. You write =IFERROR(IF(B2/C2>0.5, "High", "Low"), "Low"). A colleague says this is a bad design. Why, and what would you change?
Show answer
The fallback "Low" is identical to a legitimate result, so rows with a zero denominator look like real low values and nobody can tell them apart. Use a distinct fallback such as "Check data", or test the cause directly with =IF(C2=0, "Check data", IF(B2/C2>0.5, "High", "Low")).
Exercise
A lookup =IFERROR(VLOOKUP(A2, $F$2:$G$10, 2, FALSE), "Not listed") shows "Not listed" for every row, including names that are clearly in the table. You deleted column G last week. What is the likely cause, and which function would have exposed it?
Show answer
Deleting column G made the lookup range or column index invalid, so VLOOKUP returns #REF!, and IFERROR turns that error into "Not listed" for every row. IFNA would have replaced only #N/A and left the #REF! visible, so use IFNA when only "no match" is an acceptable outcome.
Exercise
Write one formula for D2 that returns "" when column A is empty, "Pass" when B2 divided by C2 is at least 0.5, "Fail" when it is lower, and "Check data" when the division fails. Use the pattern that avoids "Check data" appearing in unused rows.
Show answer
=IF(A2="", "", IFERROR(IF(B2/C2>=0.5, "Pass", "Fail"), "Check data")). The blank test is outermost, so empty rows return "" before any division is attempted.