Skip to content

IFERROR Function in Excel

Logic · Updated

Purpose
Return a value you choose when a formula results in an error, and the formula's own result when it does not.
Returns
The result of the formula, or the fallback value if that result is an error.
Syntax
fx=IFERROR(value, value_if_error)
Works in
Excel 2007 and later · Microsoft 365 · Google Sheets · LibreOffice Calc

Arguments

ArgumentRequiredWhat it is
valueYesThe formula, calculation or cell to check for an error.
value_if_errorYesWhat to return if value is an error. Text in double quotes, a number, a cell or another formula.

Example: replace a divide-by-zero error with text

Revenue is divided by units to get a unit price. In row 3 both are 0, so the division fails with a divide-by-zero error and IFERROR returns the text No sales. The other rows show the normal result of the same formula.

D3fx=IFERROR(B3/C3, "No sales")
ABCD
1ProductRevenueUnitsUnit price
2Notebook450.00905.00
3Pen set0.000No sales
4Stapler312.002413.00
5Folder96.00641.50
6Marker187.50752.50

Build your IFERROR formula

Fill in the fields with your own cells. The formula updates as you type.

Without the leading = sign.
Your formula
D2fx=IFERROR(B2/C2, 0)

Calculates B2/C2. If that gives any error (#N/A, #DIV/0!, #VALUE! and so on) it shows 0 instead.

Paste the formula into cell D2 or any empty cell. The coloured parts match the coloured fields. Using a different list separator? Replace the commas with semicolons.

How IFERROR works

IFERROR has two arguments. Excel calculates the first one. If the result is anything other than an error, that result is returned unchanged. If the result is an error, the second argument is returned in its place.

So =IFERROR(B2/C2, 0) behaves like =B2/C2 on every row where the division works, and returns 0 on rows where it does not.

The fallback can be text, a number, a cell reference or another formula. It is only calculated when it is needed.

Which errors IFERROR catches

IFERROR does not look at the cause. It reacts to every error value Excel can produce.

Error Usual cause
#N/A A lookup found no match.
#DIV/0! Division by zero or by an empty cell.
#VALUE! The wrong type of value, such as text in arithmetic.
#REF! A reference to a cell, column or sheet that was deleted.
#NAME? A function name or range name Excel does not recognise.
#NUM! A number that is not valid for the calculation.
#NULL! Two ranges that were expected to overlap and do not.

The first two are often expected. A product code may not be in the price list yet, or a row may have no units. The others usually mean the formula itself is wrong, and replacing them with a tidy fallback hides the problem.

More examples

Show a message when a lookup finds nothing

=IFERROR(VLOOKUP(E2, $A$2:$C$6, 3, FALSE), "Not found")

returns the looked-up value, or “Not found” when E2 is not in the first column of the table.

Return 0 when a division fails

=IFERROR(B2/C2, 0)

returns B2 divided by C2, or 0 when C2 is zero or empty.

Try a second sheet when the first has no match

=IFERROR(VLOOKUP(A2, Sheet1!$A$2:$B$100, 2, FALSE), VLOOKUP(A2, Sheet2!$A$2:$B$100, 2, FALSE))

returns the match from Sheet1 if there is one, and otherwise the result of the same lookup on Sheet2.

Convert text to a number where possible

=IFERROR(VALUE(A2), A2)

returns A2 as a number when its text can be read as one, and the original content of A2 when it cannot.

Add up a column that contains errors

=SUM(IFERROR(D2:D6, 0))

returns the total of D2:D6 with each error counted as 0. In Excel 2019 and earlier, confirm it with Ctrl+Shift+Enter.

Tips

  • Build and test the inner formula before you wrap it. Once IFERROR is in place, every failure looks the same.
  • Choose the fallback with later formulas in mind. Empty text looks clean, but "" in arithmetic with + or * produces #VALUE!. Use 0 where the cell feeds a calculation.
  • A fallback of 0 changes averages, because the cell is now counted as a number. Empty text is skipped by AVERAGE.
  • XLOOKUP has its own fourth argument for the not-found case, so =XLOOKUP(E2, A2:A6, C2:C6, "Not found") needs no IFERROR.
  • IFERROR does not catch a result that is merely wrong. A lookup that returns the wrong row passes straight through.

IFERROR or IFNA

IFNA has the same shape, =IFNA(value, value_if_na), and a narrower job.

IFERROR IFNA
Replaces Every error #N/A only
Other errors Hidden behind the fallback Still shown
Works in Excel 2007 and later Excel 2013 and later
Good for Divisions and conversions that may fail VLOOKUP, XLOOKUP and MATCH results

For a lookup, IFNA is the safer choice:

=IFNA(VLOOKUP(E2, $A$2:$C$6, 3, FALSE), "Not found")

A missing code shows “Not found”. If someone later deletes a column and the formula breaks with #REF!, you see the error and can fix it. With IFERROR the same breakage would display “Not found” on every row, which looks like a data problem and sends you looking in the wrong place.

Use IFERROR when any failure should give the same result, as with a division. For the lookups themselves, see VLOOKUP, XLOOKUP and INDEX MATCH. For a yes-or-no test that has nothing to do with errors, use IF.

Errors and fixes

ErrorWhy it happensFix
Hidden mistakeIFERROR catches every error type, so a typing mistake that causes #NAME? or a deleted column that causes #REF! shows the fallback and goes unnoticed.Get the inner formula working first, then wrap it. For lookups, use IFNA so only #N/A is replaced.
#VALUE!The fallback is empty text ("") and a later formula uses that cell in arithmetic, such as D2+D3.Use 0 as the fallback, or add the cells with SUM, which ignores text.
Fallback never showsThe inner formula returns 0 or empty text, which is a normal result. A lookup that finds an empty cell returns 0.Test for the value with IF, for example =IF(B2="", "Missing", B2).
#NAME?The function name is misspelled, or the file is open in Excel 2003 or earlier.Correct the spelling, or use IF with ISERROR in very old versions.

Questions

What is the difference between IFERROR and IFNA?

IFERROR replaces every error type. IFNA replaces only #N/A and lets other errors show. Use IFNA around lookups so that a real problem, such as #REF! or #NAME?, stays visible. IFNA needs Excel 2013 or later.

How do I use IFERROR with VLOOKUP?

Put the whole lookup in the first argument and the message in the second: =IFERROR(VLOOKUP(E2, $A$2:$C$6, 3, FALSE), "Not found"). See the VLOOKUP page for the lookup itself.

How do I make IFERROR return a blank cell?

Use two double quotes as the fallback: =IFERROR(B2/C2, ""). The cell looks empty. It holds empty text, so do not use it in arithmetic with the + operator.

Which errors does IFERROR catch?

All of them: #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME? and #NULL!.

Does IFERROR slow a workbook down?

No more than the formula inside it. The inner formula is calculated once, and its result is returned when there is no error. The older pattern with IF and ISERROR calculates the inner formula twice.

Should I wrap every formula in IFERROR?

No. Errors are useful, because they tell you something is broken. Add IFERROR where you expect a specific error and know what should be shown in its place, such as a lookup value that may be missing or a divisor that may be zero.

Related