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.

Excel 2007 and later. Also in Excel for the web and Google Sheets.

Syntax =IFERROR(value, value_if_error)

IFERROR
=IFERROR(VLOOKUP("WY",A2:B6,2,FALSE),"Add this state")

Arguments

NameRequiredWhat to pass
valueRequiredThe formula to try.
value_if_errorRequiredWhat 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

=IFERROR(VLOOKUP(D2,A2:B6,2,FALSE),"Add this state")D3
Missing state
ABCD
1StateRateLookup
2CA7.25%WY
3FL6.00%Add this state
4MA6.25%
5NY4.00%
6TX6.25%
A picture of the sheet. WY is not in column A, so VLOOKUP is #N/A and IFERROR replaces it.

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.