#!Error handling7 min read ·

How to Use IFERROR in Excel

Learn IFERROR with real examples. Replace #DIV/0! with 0, show a blank or a message, wrap a VLOOKUP or XLOOKUP and learn when IFNA is the safer choice.

Quick answer

=IFERROR(value, value_if_error)

IFERROR returns a formula's result, or a value you choose if the formula gives an error, like =IFERROR(A2/B2, 0). To replace only the #N/A from a lookup, use IFNA instead.

On this page ⌄
  1. The IFERROR syntax
  2. Replace #DIV/0! with 0
  3. Show a blank or a message instead
  4. IFERROR with VLOOKUP
  5. IFERROR with XLOOKUP
  6. IFNA: catch only #N/A
  7. Which errors IFERROR catches
  8. Test for the cause with IF instead
  9. Common IFERROR mistakes
  10. Which versions of Excel have IFERROR and IFNA?
  11. Key takeaways

IFERROR lets a formula fail gracefully. You give it a formula and a backup value. If the formula works, you get its normal result. If it returns any error, such as #DIV/0! or #N/A, you get the backup value instead:

=IFERROR(value, value_if_error)

It's the quickest way to tidy a report full of error codes. It's also easy to overuse, because it hides real mistakes too. That's where IFNA, its more careful cousin, comes in.

The examples use this team budget in A1:D7. Actual is what has been spent so far, and Training's Actual cell, C6, is still empty:

A: CategoryB: BudgetC: ActualD: Units
2Rent$2,400$2,4001
3Software$600$64512
4Travel$1,500$00
5Marketing$2,000$2,3105
6Training$8000
7Supplies$300$2760

The IFERROR syntax

ArgumentWhat it meansExample
valueThe formula to try, usually a calculation or a lookupC3/D3
value_if_errorWhat to return if value is an error: a number, text in quotes, "" or another formula0

IFERROR checks value first. If it isn't an error, IFERROR returns it unchanged, so wrapping a working formula never changes its answer. Both arguments are required.

Replace #DIV/0! with 0

Cost per unit is Actual divided by Units. For Software that works fine:

=C3/D3→ 53.75

Supplies has no units, and Excel can't divide by zero:

=C7/D7→ #DIV/0!

Wrap the division in IFERROR and give it 0 as the fallback:

=IFERROR(C7/D7, 0)→ 0
=IFERROR(C3/D3, 0)→ 53.75

A result without an error passes straight through. You'll also get #DIV/0! when you divide by an empty cell, because Excel treats it as 0 in a calculation.

Your turn. Travel has no units yet either, so dividing its Actual by its Units fails. Fix it so the cell shows 0.

Try it yourself

A live spreadsheet. Type a formula and press Enter to check it.

Exercise 1 of 11IFERROR

Work out the cost per unit for Travel (Actual ÷ Units). Units is 0, so show 0 instead of an error.

Write your formula in the green cell, G2.

team-budget.xlsx
fx
1CategoryBudgetActualUnits
2Rent$2,400.00$2,400.001Travel/unit
3Software$600.00$645.0012
4Travel$1,500.00$0.000
5Marketing$2,000.00$2,310.005
6Training$800.000
7Supplies$300.00$276.000
8
9
10

Click a cell to add it to your formula, drag to select a range, or click a column letter for the whole column.

Show a blank or a message instead

The fallback can also be text in double quotes. Training has no units either:

=IFERROR(C6/D6, "Not yet")→ Not yet

To make the cell look empty, use two double quotes with nothing between them:

=IFERROR(C7/D7, "")

That empty text has side effects, because the cell now holds text rather than nothing. If E7 contains the formula above:

=E7*2→ #VALUE!
=ISBLANK(E7)→ FALSE

SUM and AVERAGE skip text, so column totals still work, but arithmetic on the cell itself breaks. Use "" for cells people read, and 0 for results other formulas use.

IFERROR with VLOOKUP

A lookup that can't find its value returns #N/A. There's no Utilities row in the budget:

=VLOOKUP("Utilities", A2:D7, 2, FALSE)→ #N/A
=IFERROR(VLOOKUP("Utilities", A2:D7, 2, FALSE), "Not found")→ Not found
=IFERROR(VLOOKUP("Marketing", A2:D7, 3, FALSE), "Not found")→ $2,310

When the value is there, you get the normal result. In a real sheet, point at a cell and lock the table before copying down:

=IFERROR(VLOOKUP(F2, $A$2:$D$7, 2, FALSE), "Not found")

If a value you can see in the list comes back as "Not found", look for an extra space or a number stored as text. The VLOOKUP guide has a checklist for #N/A.

IFERROR also won't help with blanks, because a blank isn't an error. Training is in the list, but its Actual cell is empty, and VLOOKUP returns an empty cell as 0:

=IFERROR(VLOOKUP("Training", A2:D7, 3, FALSE), "Not found")→ 0

That 0 makes it look as if Training spent nothing. If blanks matter, test for them with IF first.

The fallback can even be another lookup. If last year's categories are on a sheet named Archive, this tries the Archive list only when the first lookup fails:

=IFERROR(VLOOKUP(F2, A2:D7, 2, FALSE), IFERROR(VLOOKUP(F2, Archive!A2:D20, 2, FALSE), "Not found"))

IFERROR with XLOOKUP

XLOOKUP has its own fourth argument, if_not_found, for exactly this job:

=XLOOKUP("Utilities", A2:A7, B2:B7, "Not found")→ Not found

That's usually better than wrapping XLOOKUP in IFERROR, because if_not_found only steps in when there's no match. Other mistakes still show. Here the return range is one row short:

=XLOOKUP("Rent", A2:A7, B2:B6, "Not found")→ #VALUE!
=IFERROR(XLOOKUP("Rent", A2:A7, B2:B6), "Not found")→ Not found

The first formula tells you something is wrong. The second claims Rent isn't in the budget, when it's in the very first row. See the XLOOKUP guide for its other optional arguments.

IFNA: catch only #N/A

IFNA works like IFERROR, but it only replaces #N/A, the "not found" error. Every other error gets through:

=IFNA(value, value_if_na)

Here's why that matters. This VLOOKUP has a mistake in it: A2:D7 has four columns, but the formula asks for the 5th.

=IFERROR(VLOOKUP("Marketing", A2:D7, 5, FALSE), "Not found")→ Not found
=IFNA(VLOOKUP("Marketing", A2:D7, 5, FALSE), "Not found")→ #REF!

Marketing is right there in row 5. IFERROR turns the #REF! into a believable but wrong "Not found". IFNA lets the #REF! through, so you spot the bad column number and fix it. When the value really is missing, both give the same answer:

=IFNA(VLOOKUP("Utilities", A2:D7, 2, FALSE), "Not found")→ Not found

So which should you use?

  • VLOOKUP, or INDEX and MATCH: use IFNA. The INDEX and MATCH guide shows it in action.
  • XLOOKUP: use its if_not_found argument.
  • Calculations where one error is expected, like dividing by a cell that can be 0: IFERROR is fine, or test for the cause with IF, as shown below.

Which errors IFERROR catches

IFERROR catches all of these. IFNA catches only #N/A.

ErrorBudget exampleWhat went wrong
#DIV/0!=C7/D7Dividing by zero or an empty cell
#N/A=MATCH("Utilities", A2:A7, 0)A lookup found no match
#VALUE!=A2*2The wrong type of value, like text in a calculation
#REF!=INDEX(B2:B7, 7)A reference outside the range, here the 7th cell of 6
#NAME?=SUMM(B2:B7)A misspelled function, or text without quotes
#NUM!=SQRT(C7-B7)An impossible number, here the square root of -24
#NULL!=SUM(B2:B7 C2:C7)A space between two ranges that don't overlap
#CALC!=FILTER(A2:A7, D2:D7>20)FILTER found nothing to return
#SPILL!=FILTER(A2:A7, D2:D7>0)The 3 results are blocked by a cell that isn't empty

The last two only appear in Microsoft 365 and Excel 2021 or later. Like XLOOKUP, FILTER has its own fallback argument: =FILTER(A2:A7, D2:D7>20, "None") returns None.

The one thing IFERROR can't fix is a blocked spill in its own cell. The formula itself worked, and the problem is the cells in the way, so clear them instead.

Test for the cause with IF instead

When you know which error to expect, testing for its cause is often clearer. For a divisor that can be 0:

=IF(D7=0, 0, C7/D7)→ 0

This only handles the zero. If C7 held text by mistake, you'd still see #VALUE!, which is what you want.

Older files may use =IF(ISERROR(C7/D7), 0, C7/D7), the way people wrote this before IFERROR. It repeats the formula, so swap in IFERROR when you can.

Common IFERROR mistakes

ProblemWhat's going onFix
"Not found" for a value that's in the listIFERROR is hiding another error, like a wrong column numberUse IFNA, or remove IFERROR and look at the real error
#NAME? instead of your messageText without quotes, like =IFERROR(C7/D7, None)Put quotes around text: "None"
0 where you expected the fallbackThe lookup found an empty cell, and that's 0, not an errorTest for blanks with IF
#VALUE! further down the sheetThe fallback was "", and another formula does math with itUse 0 when other formulas use the result

Which versions of Excel have IFERROR and IFNA?

IFERROR works in Excel 2007 and every version since, including Microsoft 365 and Excel for the web. IFNA arrived in Excel 2013, so use IFERROR if the file has to work in Excel 2010 or older. Google Sheets has both.

For more practice, the error handling topic has a free IFNA lookup, plus Premium exercises on IFERROR with a message and IFNA with MATCH.

Key takeaways

  • =IFERROR(value, value_if_error) returns the formula's result, or your fallback if the formula gives any error.
  • Use 0 as the fallback when other formulas use the result, and "" only for display.
  • For lookups, prefer IFNA or XLOOKUP's if_not_found, so real mistakes still show.
  • IFERROR doesn't treat blanks as errors. A lookup that lands on an empty cell still returns 0.

Practice

Keep going with IFERROR and IFNA exercises

Reading gets you started. Solving a few of these is what makes it stick.

  1. 1Avoid #DIV/0!FreeWork out the cost per unit for Travel (Actual ÷ Units). Units is 0, so show 0 instead of an error.→
  2. 2Missing lookupsFreeLook up the budget for Events. It isn't in the table, so return "No budget".→
  3. 3IFERROR with a message PremiumWork out the cost per unit for Supplies (Actual ÷ Units). It has no units, so show "No units" instead of an error.→
  4. 4IFNA with MATCH PremiumFind the position of "Hardware" in the Category list. It isn't there, so return "Missing" instead of #N/A.→
  5. 5When it's not there PremiumLook up the name of employee E110. That ID doesn't exist, so return "Not found" instead of an error.→
All error handling exercises →
Brian Millot

About the author

Brian Millot

Brian Millot is an indie hacker based in France who builds small, focused web products. He built and runs Excel Formula Practice, from the in-browser spreadsheet that checks your formulas to the exercise library, and he writes the formula guides.

Related guides

Practice makes formulas

Stop reading. Start typing formulas.

Every exercise is a real spreadsheet with instant feedback. The first two in every topic are free, no sign-up needed.