Function · Logical
Excel IFERROR function
The Excel IFERROR function replaces any error with a value you choose. A missing state code returns the words Add this state.
Syntax =IFERROR(value, value_if_error)
=IFERROR(VLOOKUP("WY",A2:B6,2,FALSE),"Add this state")Arguments
| Name | Required | What to pass |
|---|---|---|
| value | Required | The formula to try. |
| value_if_error | Required | What to return if value is any error, including #N/A, #DIV/0!, #VALUE!, #REF!, and #NAME?. |
Examples
Wyoming is not in a five-state rate table
=IFERROR(VLOOKUP("WY",A2:B6,2,FALSE),"Add this state")Result Add this state
| A | B | C | D | |
|---|---|---|---|---|
| 1 | State | Rate | Lookup | |
| 2 | CA | 7.25% | WY | |
| 3 | FL | 6.00% | Add this state | |
| 4 | MA | 6.25% | ||
| 5 | NY | 4.00% | ||
| 6 | TX | 6.25% |
IFERROR runs a formula and, if that formula is any error, returns your fallback instead. A VLOOKUP of WY in a table that only holds CA, FL, MA, NY, and TX is #N/A. Wrapping it returns the words Add this state, which is what you want on a rate sheet. Returning 0 would mean “this state has no tax” and would undercharge the customer.
The cost is that IFERROR also hides #REF!, #NAME?, and #DIV/0!. A misspelled function name then looks like a missing state. IFNA, in Excel 2013 and later, catches only #N/A. Prefer that for lookups. XLOOKUP has the fallback built in and does not need the wrapper.