Sub topic 10
IFERROR: providing a fallback when a formula fails
Prerequisites: You should know how to enter Google Sheets formulas, use cell references such as C2, and write basic IF formulas. This chapter assumes you can recognize a formula error and edit the formula that caused it.
What IFERROR does
IFERROR evaluates a formula and returns one result when the formula works and another result when it produces any error.
Its syntax is:
=IFERROR(value, value_if_error)The value argument is the formula to evaluate. The value_if_error argument is the fallback to return if that formula fails.
For example, this formula divides a total by a count:
=IFERROR(C2/D2,0)If D2 contains 4, the formula returns the result of C2/4. If D2 is zero or blank, the division may produce #DIV/0!, so IFERROR returns 0.
The fallback can be text, a number, a blank string, or another formula:
=IFERROR(VLOOKUP(A2,Prices!A:B,2,FALSE),"Not found")When the lookup succeeds, the formula returns the price. When the lookup produces an error, it returns Not found.
How the decision works
The following model shows the two paths through IFERROR.
IFERROR catches all error values, including the common ones below.
| Error | Typical cause |
|---|---|
| `#N/A` | A lookup or match found no result |
| `#DIV/0!` | A number was divided by zero |
| `#VALUE!` | A function received the wrong kind of value |
| `#REF!` | A formula refers to a deleted or invalid cell |
| `#NAME?` | Sheets does not recognize a function or name |
| `#NUM!` | A calculation uses an invalid numeric value |
A fallback should help the person using the sheet understand the result. For example, 0 can be useful for a missing count, while "Check input" is better when a calculation may contain bad data.
Combining IFERROR with IFS
You can wrap an IFS formula in IFERROR to handle invalid or incomplete input. The inner formula handles valid conditions. The outer formula handles errors.
=IFERROR(IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F"),"Check score")For a valid numeric score, the formula returns a letter grade. If B2 contains a value that prevents the comparisons from working, the formula returns Check score.
The final TRUE condition handles valid scores below 70. IFERROR handles failures that are different from an ordinary low score.
Combining IFERROR with SWITCH
SWITCH is useful when one expression should match exact values. You can use IFERROR outside it when the expression or one of its cases may fail.
=IFERROR(SWITCH(A2,"NY","New York","CA","California","TX","Texas","Unknown"),"Check code")The default value "Unknown" handles a code that does not match a listed case. The outer fallback "Check code" handles an actual error in A2 or in the formula.
Avoid hiding mistakes
IFERROR is convenient, but a broad fallback can hide a broken formula. For example:
=IFERROR(A2/B2,"")This displays a blank for every error. A zero denominator, a deleted reference, and invalid text all look the same. That makes debugging harder.
Use a specific fallback while developing the sheet:
=IFERROR(A2/B2,"Check amount and denominator")After the formula is tested, choose a display value that fits the purpose of the sheet. Keep the underlying cause visible when an error signals a data-quality problem.
Exercise
Write a formula that divides C2 by D2 and displays "No denominator" if the calculation produces an error.
Show answer
=IFERROR(C2/D2,"No denominator")