Sub topic 4
Catching only #N/A with IFNA
What this chapter assumes
You should already know how to enter and copy formulas, how relative and absolute references work, and how to use IF and VLOOKUP. The previous chapter covered IFERROR, which catches every error type. This chapter covers IFNA, which catches only one.
What IFNA does
IFNA returns a value you choose when a formula produces #N/A. For any other result, including other errors, it returns the formula's own result unchanged.
The syntax is:
=IFNA(value, value_if_na)valueis the formula or reference to evaluate.value_if_nais what to return ifvalueis#N/A.
#N/A means "not available". Lookup functions such as VLOOKUP, HLOOKUP, MATCH and XLOOKUP return it when they cannot find the lookup value. In most workbooks a missing lookup match is an expected situation, not a mistake in the formula. That makes #N/A the one error you can usually handle safely.
IFNA is available in Excel 2013 and later. Earlier versions need IF(ISNA(...), ...).
A basic example
Suppose column A holds product codes, column B holds prices, and E2 holds a code typed by a user. This formula looks up the price and shows a message if the code is not in the list:
=IFNA(VLOOKUP(E2, $A$2:$B$100, 2, FALSE), "Not found")The formula behaves like this:
- If E2 is in the list, VLOOKUP returns the price and IFNA passes it through.
- If E2 is missing, VLOOKUP returns
#N/Aand IFNA returns "Not found". - If the formula has a different problem, the error still appears. For example, if the range were deleted and the formula showed
#REF!, IFNA would not hide it.
That last point is the reason to prefer IFNA for lookups.
How the evaluation flows
IFNA compared with IFERROR
Both functions take two arguments, but their reach differs. The same lookup, written with each, behaves differently when something is broken.
| Situation | `IFNA(..., "Not found")` | `IFERROR(..., "Not found")` |
|---|---|---|
| Code is missing from the list | Not found | Not found |
| Lookup range was deleted (`#REF!`) | `#REF!` | Not found |
| Function name misspelled (`#NAME?`) | `#NAME?` | Not found |
| Column index is too large (`#REF!`) | `#REF!` | Not found |
With IFERROR, a broken formula looks the same as a normal "missing" result. With IFNA, the break stays visible so you can fix it.
Common errors when using IFNA
- Expecting it to fix
#DIV/0!. IFNA does nothing for division errors. Use a check such as=IF(B2=0, "", A2/B2)for that case. - Wrapping too much. Put IFNA around the lookup, not around a large calculation. Otherwise an unrelated
#N/Adeep inside the formula gets replaced by your message. - Using a blank string and then doing math.
""is text, not an empty cell. A later formula such as=F2*2returns#VALUE!if F2 holds"". - Assuming a missing match is the only cause of
#N/A. A lookup value with a trailing space, or a number stored as text, also returns#N/A. IFNA will hide that mismatch and show "Not found" even though the item is in the list.
Testing for a missing value
Sometimes you want a label rather than a lookup result. ISNA returns TRUE only for #N/A, so it fits an IF test:
=IF(ISNA(MATCH(E2, $A$2:$A$100, 0)), "Missing", "Found")MATCH with match type 0 requires an exact match. If E2 is not in the list, MATCH returns #N/A, ISNA returns TRUE, and the formula shows "Missing".
Try it
- Put codes in A2:A6 and prices in B2:B6.
- In E2, type a code from the list. Enter the IFNA formula above in F2 and confirm it returns the price.
- Change E2 to a code that is not in the list. Confirm F2 shows "Not found".
- Change the lookup range to
$A$2:$B$100with a column index of 5. Confirm F2 shows#REF!rather than "Not found".
Exercise
A VLOOKUP wrapped in IFNA shows "Not found" for a code you can see in the list. The formula and range are correct. Name two likely causes and how to check each one.
Show answer
The lookup value or the list entry may contain a trailing or leading space, which you can check by comparing LEN(E2) with LEN of the list cell or by wrapping the value in TRIM. Alternatively, one side may be a number and the other text, which you can check with ISNUMBER on both cells. Both cases return #N/A, so IFNA turns them into "Not found".
Exercise
Why does =IFNA(A2/B2, 0) not protect against a blank B2?
Show answer
A blank B2 makes the division return #DIV/0!, not #N/A. IFNA passes #DIV/0! through unchanged. Use IFERROR, or test the divisor with IF(B2=0, 0, A2/B2).