Sub topic 5
IFERROR or IFNA: which one to use
This chapter assumes you can enter and copy formulas, use relative and absolute references, and write a basic IF and VLOOKUP. It also assumes you have met the error values (#DIV/0!, #N/A, #VALUE!, #REF!, #NAME?, #NUM!, #NULL!) and have seen the syntax of both IFERROR and IFNA. Here the focus is on choosing between them and on the mistakes that follow from choosing badly.
The core difference
Both functions take a value and a fallback. If the value is an error, they return the fallback. If it is not an error, they return the value unchanged.
=IFERROR(value, value_if_error)
=IFNA(value, value_if_na)The difference is which errors count:
| Function | Catches | Lets through |
|---|---|---|
| IFERROR | All seven error types | Nothing |
| IFNA | Only #N/A | #DIV/0!, #VALUE!, #REF!, #NAME?, #NUM!, #NULL! |
IFERROR is a broad net. IFNA is a narrow one. The right choice depends on which failure you expect and which failures you want to see.
Why #N/A is special
#N/A means "value not available". Lookup functions such as VLOOKUP, HLOOKUP, MATCH and XLOOKUP (without its fourth argument) return it when the item you searched for is not in the list. For a lookup, this is often a normal outcome. A new product code may not have a price yet, or a customer may not be in the list.
The other errors usually point to a defect:
- #REF! means a formula points to a cell or column that was deleted.
- #NAME? means a function name is misspelled or a named range does not exist.
- #VALUE! means an argument has the wrong type, such as text in arithmetic.
- #NUM! means a number is invalid for the operation.
- #DIV/0! can be a normal outcome, but it can also signal missing data.
A missing lookup match is something you can plan for. A deleted column is a bug you need to fix. IFNA handles the first and leaves the second visible.
A side-by-side example
Suppose column A holds product codes and column B holds prices on a list at A2:B100. Cell E2 holds a code to look up.
=IFERROR(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")With a code that is not in the list, both formulas return "Not found". The two formulas differ when something else goes wrong. Suppose someone deletes column B. The lookup now returns #REF!, because the column index 2 or the range reference is broken.
- The IFERROR version shows "Not found" for every row. The message is false, because the codes may well exist. Nothing signals that the formula is broken.
- The IFNA version shows #REF!. The problem is visible and you can trace it.
The IFNA formula fails loudly when it should, and the IFERROR formula fails silently.
When IFNA is the right choice
Use IFNA when the only failure you expect is a missing match. That covers most lookup work:
- VLOOKUP, HLOOKUP and INDEX/MATCH with an exact match.
- Checking whether a value appears in another list.
- Merging two tables where some keys have no partner.
Here the formula that handles the missing key also needs the other errors to surface:
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")If the price column contains an error of its own, such as a #DIV/0! produced by an upstream formula, VLOOKUP returns that error. IFNA lets it through, so you see that the source data is faulty. IFERROR would replace it with "Not found", which would misreport a data problem as a missing key.
When IFERROR is the right choice
Use IFERROR when several errors are possible and you have decided that all of them should produce the same fallback. This is reasonable when:
- The result goes to a report or chart where an error value would look broken, and you have already checked the inputs.
- The formula is a calculation with a known, harmless failure, such as a ratio on a row with no data.
- The formula parses messy text and any failure means "not usable".
The standard example is a division:
=IFERROR(A2/B2, 0)This returns 0 when B2 is zero. It also returns 0 when B2 contains text (#VALUE!), when A2 or B2 refers to a deleted cell (#REF!), or when either one holds an error from another formula. For a quick personal worksheet that is often acceptable. In a model other people rely on, it is a risk, as the next section shows.
The risk with IFERROR
IFERROR hides errors you did not anticipate. Common ways this goes wrong:
- A misspelled function name.
=IFERROR(VLOOKUPP(E2, A:B, 2, FALSE), 0)returns 0 for every row. The #NAME? error is swallowed, so the formula appears to work. - A broken reference. After a column is deleted, every row shows the fallback and totals shrink without warning.
- Numbers stored as text. A lookup for the number 1001 against text "1001" returns #N/A. Both functions catch this, so even IFNA cannot tell "not in the list" from "wrong data type". Check your data types separately.
- Wrong arguments. A column index larger than the range width gives #REF!. IFERROR hides it, IFNA does not.
The numbers-as-text case shows the limit of IFNA. It catches only #N/A, but #N/A has more than one cause. Narrowing the function reduces the risk, and it does not remove it.
Wrapping scope: wrap the smallest piece
You can reduce the risk of either function by wrapping only the part of the formula that is expected to fail. Compare:
=IFERROR(SUM(VLOOKUP(E2, $A$2:$B$100, 2, FALSE) * C2, D2), 0)=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), 0) * C2 + D2In the first formula, one wrapper covers the lookup, the multiplication and the sum. Any error anywhere becomes 0. In the second, only the lookup is guarded, and only #N/A is replaced. If C2 holds text, the formula returns #VALUE!, which is correct.
Notice also that this changes the arithmetic. A missing price becomes 0, so the product is 0 and D2 is still added. That may or may not be what you want, which is the subject of choosing a replacement value.
Replacement values change what follows
The fallback is not only a display choice. Other formulas read it.
| Fallback | Type | Effect on SUM and AVERAGE | Effect on later arithmetic |
|---|---|---|---|
| 0 | Number | Counted. Lowers an average. | Works, but a missing value looks like a real zero. |
| "" | Text | Ignored by SUM and AVERAGE. | `=A2+1` gives #VALUE! if A2 is "". |
| "Not found" | Text | Ignored by SUM and AVERAGE. | Arithmetic on it gives #VALUE!. |
A concrete case: three rows return 10, 20 and an error. With IFERROR(..., 0) the average is 10. With IFERROR(..., "") the average is 15, because the text is skipped. Neither is wrong, but they answer different questions. Decide which one matches the meaning of "no data" in your report.
An empty string also looks like an empty cell but is not one. ISBLANK returns FALSE for it, and COUNTA counts it. Using "" can therefore break a later formula that tests for blanks.
=IFERROR(A2/B2, "")If this cell feeds =C2*2, the result is #VALUE! on the rows where C2 is "". That moves the error one step downstream and makes it harder to trace.
A decision guide
Work through these questions in order:
- Can the formula fail in a way you expect and accept? If the expected failure is a missing lookup match, use IFNA.
- Is the expected failure something other than #N/A? For a zero divisor, a precheck with IF is more precise than IFERROR (see below).
- Do you truly want every error replaced? Only then use IFERROR, and wrap the smallest part of the formula.
- Does the fallback need to be used in later arithmetic? If so, use a number. If it is only for display, text is fine.
Prevent instead of catch
Sometimes the best answer is neither function. A test with IF handles exactly the case you have in mind and nothing else:
=IF(B2=0, "", A2/B2)This returns "" only when the divisor is zero. If B2 holds text or A2 holds an error, the division still shows its error. You trade a little more typing for precision.
For lookups, XLOOKUP has the same idea built in. Its fourth argument supplies a value for a missing match, and other errors still show:
=XLOOKUP(E2, $A$2:$A$100, $B$2:$B$100, "Not found")This is equivalent to the IFNA form and shorter. Use it when your Excel version supports XLOOKUP.
You can also test for a missing match without returning a value from the lookup:
=IF(ISNA(MATCH(E2, $A$2:$A$100, 0)), "Missing", "Found")Note that ISERROR, like IFERROR, matches every error type. ISNA, like IFNA, matches only #N/A. The choice between the two test functions follows the same logic as the choice between the two wrappers.
Common mistakes
- Using IFERROR by habit. It works on the first try, so it becomes the default. Switch to IFNA for lookups.
- Wrapping an entire long formula. Wrap only the risky part.
- Choosing "" and then doing arithmetic on it. Use 0 when later formulas need numbers.
- Leaving no trace. Consider a visible count of fallbacks, such as
=COUNTIF(F2:F100, "Not found"), so a sudden jump tells you something changed. - Treating IFNA as a complete safeguard. A wrong data type still produces #N/A. Clean your keys with TRIM, VALUE or TEXT as needed.
Quick reference
| Situation | Best choice |
|---|---|
| Exact-match lookup where a missing key is normal | IFNA, or XLOOKUP with if_not_found |
| Division where only a zero divisor is expected | IF(B2=0, ...) |
| Report cell where any failure should show a neutral value, inputs already validated | IFERROR on the smallest part |
| Testing whether a key exists | ISNA with MATCH |
| Any formula where you want to see unexpected problems | IFNA or a precheck, not IFERROR |
Exercise
A workbook uses =IFERROR(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), 0) to fetch prices. After someone deletes column B, every price shows 0 and the order total drops sharply, but no error appears. Explain why, and write a formula that would have made the problem visible while still returning 0 for codes that are truly missing.
Show answer
Deleting column B makes the lookup range or column index invalid, so VLOOKUP returns #REF!. IFERROR catches every error type, so it replaces #REF! with 0 and hides the fault. Use IFNA instead: =IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), 0). Missing codes (#N/A) still return 0, but #REF! passes through and shows the broken formula.
Exercise
Cells F2:F5 contain 10, 20, 30 and an #N/A produced by a lookup. You change the lookup formula so the fourth cell returns "" instead of #N/A. What does =AVERAGE(F2:F5) return, and what would it return if the fallback were 0? Which fallback is safer if G2 contains =F5*2?
Show answer
With "", AVERAGE ignores the text and returns 20 (60 divided by 3). With 0, it returns 15 (60 divided by 4). The fallback 0 is safer for =F5*2, because it returns 0. With "" the formula returns #VALUE!, since arithmetic on text fails.
Exercise
Write a formula for H2 that returns the ratio of A2 to B2, shows a blank only when B2 is zero, and still shows any other error.
Show answer
=IF(B2=0, "", A2/B2). The test handles only the zero divisor. If B2 is text, or A2 or B2 holds an error, the division still produces its own error value, so the problem stays visible.