Menu

IFERROR in Excel: Replace #N/A and #DIV/0! (and IFNA)

=IFERROR(B2/C2,0) returns B2/C2, or 0 when the division gives an error. Learn IFERROR with VLOOKUP, returning a blank instead of an error, why IFNA is the better choice for lookups, and why hiding every error can hide real mistakes.

Every sheet on this page is live: change a number or a formula and it recalculates.

=IFERROR(B2/C2,0) returns the result of B2/C2, or 0 when that result is an error. The first argument is the formula you want; the second is what to show instead of any error it produces.

Price per unit
E2
ABCDE
1ProductRevenueUnitsPlainWith IFERROR
2Pens$12080$1.50$1.50
3Paper$30050$6.00$6.00
4Ink$900#DIV/0!$0.00
5Tape$4530$1.50$1.50
6Clips$00#DIV/0!$0.00
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Ink and Clips have 0 units, so the plain division in column D shows #DIV/0!. Column E shows $0.00 for them and the normal price for every other row. Type 15 in C4 and both columns show Ink's price.

IFERROR syntax

=IFERROR(value, value_if_error)
  • value is the formula to calculate.
  • value_if_error is returned when value is any error: #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, #NULL!, and the newer ones such as #CALC!.
  • If value is not an error, IFERROR returns it unchanged.

The replacement can be a number (0), text ("Not found"), empty text ("") or another formula, for example a second lookup in another table: =IFERROR(VLOOKUP(E2,A2:C6,3,FALSE),VLOOKUP(E2,G2:I6,3,FALSE)).

IFERROR with VLOOKUP

A lookup returns #N/A when the value is not in the table. Wrapping it in IFERROR shows a message instead:

Look up a price
F2
ABCDEF
1ProductCategoryPriceLook forPrice
2AppleFruit$1.20Pear$1.50
3PearFruit$1.50KiwiNot found
4CarrotVegetable$0.80Milk$1.10
5BreadBakery$2.40
6MilkDairy$1.10
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Kiwi is not in the list, so F3 says Not found. Type Kiwi in A4 instead of Carrot and F3 finds it. With XLOOKUP you do not need IFERROR for this, because its fourth argument is the "not found" value: =XLOOKUP(E2,A2:A6,C2:C6,"Not found").

IFNA: catch only #N/A

IFNA works like IFERROR but only replaces #N/A. For lookups that is usually what you want: #N/A means "not found", which is a normal answer, while any other error means the formula itself is wrong. In this sheet the formulas ask for column 4 of a three-column table, a typo:

IFERROR hides a typo, IFNA shows it
F2
ABCDEFG
1ProductCategoryPriceLook forIFERRORIFNA
2AppleFruit1.2PearNot found#REF!
3PearFruit1.5
4CarrotVegetable0.8
5BreadBakery2.4
6MilkDairy1.1
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Pear is in the table, yet F2 says Not found: IFERROR turned the #REF! from the bad column number into the same message as a missing product. G2 lets the #REF! through, so you see that the formula is broken. Change the 4 to 3 in G2 and it returns 1.5. IFNA needs Excel 2013 or later.

Return a blank instead of an error

To show nothing, use empty text, two double quotes, as the replacement:

Growth with blanks for errors
D2
ABCD
1MonthLast yearThis yearGrowth
2Jan20024020%
3Feb0150
4Mar180171-5%
5Apr90
6May25030020%
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

February and April had no sales last year, so their growth cannot be calculated and the cell stays empty. The other months show 20%, minus 5% and 20%. A cell with "" holds text: SUM and AVERAGE skip it, but =D3*2 gives #VALUE!. If later formulas do arithmetic on the column, return 0 instead.

Practice: look up with a fallback

Stock lookup
F2
ABCDEF
1ProductStockLook forStock
2Apple40Kiwi
3Pear25
4Carrot60
5Bread12
6Milk30
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In F2, look up the stock of the product in E2 from A2:B6, and show "Not found" when it is not in the list.

Why hiding every error can hide mistakes

IFERROR does not fix anything; it decides what the cell shows. Before you wrap a formula in it:

  1. Find out why the error happens. When a blank Units cell causes #DIV/0!, the real fix may be data that someone should enter, not a zero price.
  2. Prefer IFNA for lookups, so that a wrong column number (#REF!), a misspelled name (#NAME?) or text in a number column (#VALUE!) still shows.
  3. Test the specific case for divisions. =IF(C2=0,0,B2/C2) handles a zero divisor and nothing else; a wrong reference in B2 still shows its error. The page on #DIV/0! compares the two approaches.
  4. Pick a replacement that cannot be mistaken for data. A 0 in a price column looks like a real price and lowers the average; "" or "Not found" does not.

Wrap the formula last, once it gives the right result on the rows that should work.

Frequently Asked Questions

How do I use IFERROR with VLOOKUP?

Wrap the lookup: =IFERROR(VLOOKUP(E2,A2:C6,3,FALSE),"Not found"). When E2 is not in the first column, the cell shows Not found instead of #N/A. =IFNA(VLOOKUP(E2,A2:C6,3,FALSE),"Not found") does the same and still shows other errors.

How do I make IFERROR return a blank cell?

Use empty text as the second argument: =IFERROR(B2/C2,""). The cell looks empty, but it holds text, so =D2+1 on it gives #VALUE!; SUM and AVERAGE skip it.

What is the difference between IFERROR and IFNA?

IFERROR replaces every error: #N/A, #DIV/0!, #VALUE!, #REF!, #NAME?, #NUM! and #NULL!. IFNA replaces only #N/A, the "not found" of lookups, and lets every other error show, so a broken formula is not hidden.

How do I replace #N/A with 0 in Excel?

Wrap the formula in IFNA with 0 as the value: =IFNA(VLOOKUP(E2,A2:C6,3,FALSE),0). XLOOKUP has the replacement built in as its fourth argument: =XLOOKUP(E2,A2:A6,C2:C6,0).

Which Excel versions have IFERROR and IFNA?

IFERROR exists since Excel 2007 and IFNA since Excel 2013. In older files you may see =IF(ISERROR(B2/C2),0,B2/C2), which does the same job as IFERROR but calculates the formula twice.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED