Sub topic 8
Fixing #N/A: lookups that find nothing
This chapter assumes you can enter formulas, use cell references and ranges such as A2:B100, and have used VLOOKUP at least once. It also assumes you know that Excel treats numbers and text as different kinds of values.
What #N/A means
#N/A stands for "not available." A lookup function returns it when it searches for a value and cannot find a match. Unlike most other errors, #N/A often means the formula is working as designed. It reports that the answer does not exist in the data you pointed it at.
That makes #N/A different from #REF! or #NAME?, which usually mean the formula itself is broken. With #N/A, you have to ask two questions:
- Is the value really missing from the lookup table?
- Is the value present, but written in a way that Excel does not treat as equal?
The first case is expected, and you can handle it with a friendly message. The second case is a data or formula problem, and you should fix it at the source.
The usual causes
Most #N/A results from lookups come from a short list of causes.
| Cause | Example | Fix |
|---|---|---|
| The value is not in the table | Looking up product `P-900` when the list stops at `P-500` | Add the row, or handle the miss with IFNA |
| Extra spaces | `"Smith "` in the data, `"Smith"` in the lookup | Clean with `TRIM` |
| Number versus text mismatch | `1001` as a number against `"1001"` as text | Convert one side so both match |
| Lookup column is not the first column | VLOOKUP searches only the leftmost column of the table | Move the column, or use INDEX with MATCH |
| Range does not cover the data | `A2:B50` when data runs to row 100 | Extend the range |
| Wrong match mode | Last argument omitted or `TRUE` on unsorted data | Use `FALSE` for an exact match |
A basic lookup that fails
Suppose column A holds product codes and column B holds prices, in A2:B100. Cell E2 contains the code you want.
=VLOOKUP(E2,A2:B100,2,FALSE)The 2 asks for the second column of the table, which is the price. The FALSE asks for an exact match. If E2 holds a code that is not in A2:A100, the formula returns #N/A.
The same applies to MATCH, HLOOKUP and XLOOKUP, which all report a missing value as #N/A by default.
Handling expected misses with IFNA
When a missing value is a normal outcome, replace the error with a readable result. IFNA is the best fit because it replaces only #N/A.
=IFNA(VLOOKUP(E2,A2:B100,2,FALSE),"Not found")Other errors still show. If someone deletes column B, the formula returns #REF! and you see it. With IFERROR, that real problem would be replaced by "Not found" and stay hidden.
The next two formulas look similar but behave differently.
=IFERROR(VLOOKUP(E2,A2:B100,2,FALSE),"Not found")
=IFNA(VLOOKUP(E2,A2:B100,2,FALSE),"Not found")If the lookup range is deleted, the first returns "Not found" and the second returns #REF!. The second is safer because the broken formula remains visible.
Diagnosing a lookup that should have matched
If you can see the value in the table but the lookup still returns #N/A, the two values differ in a way that is hard to see. Work through these checks in order.
Check for extra spaces
A cell that shows Smith may actually contain Smith with a trailing space. Excel treats these as different values. To test, compare lengths:
=LEN(E2)Compare the result with the number of visible characters. If it is larger, there are hidden spaces. Clean the lookup value inside the formula:
=VLOOKUP(TRIM(E2),A2:B100,2,FALSE)TRIM removes leading and trailing spaces and reduces repeated spaces between words to one. If the spaces are in the table rather than the lookup value, clean the table column itself. A cleaning formula in a helper column, copied and pasted back as values, is a reliable approach.
Check for number versus text mismatch
A lookup value of 1001 (a number) does not match a table entry of "1001" (text), even though they look identical. Signs of text numbers include left alignment, a small green triangle in the corner of the cell, and a leading apostrophe visible in the formula bar.
To convert text to a number in the lookup value:
=VLOOKUP(VALUE(TRIM(E2)),A2:B100,2,FALSE)If instead the table holds text and your lookup value is a number, convert the number to text by joining it with an empty string:
=VLOOKUP(E2&"",A2:B100,2,FALSE)Making the mismatch disappear at the data source is better than patching each formula. Converting the whole column once means every later lookup works.
Check the match mode
The fourth argument of VLOOKUP controls how matching works.
FALSE(or0) means exact match. The data can be in any order.TRUE(or1, or omitted) means approximate match. The data must be sorted in ascending order, or results can be wrong or#N/A.
For code lookups and names, you almost always want FALSE. Approximate matching is meant for things like tax bands or grade thresholds, where you want the largest value that does not exceed the lookup value.
With approximate matching, #N/A appears when the lookup value is smaller than the first value in the sorted column. There is no band below the first one, so nothing fits.
Check the table range
VLOOKUP searches only the first column of the table you give it. In A2:B100, it searches column A. If the key you want to find is in column B and the answer is in column A, VLOOKUP cannot do it, and it returns #N/A.
A related problem happens when you copy a formula down. A reference such as A2:B100 shifts to A3:B101, then A4:B102, and the table slips away from the data. Lock the table with absolute references:
=VLOOKUP(E2,$A$2:$B$100,2,FALSE)When you copy this formula down, only E2 changes.
Looking left with INDEX and MATCH
When the key sits to the right of the answer, use MATCH to find the row and INDEX to return a value from that row.
=INDEX($A$2:$A$100,MATCH(E2,$B$2:$B$100,0))MATCH(E2,$B$2:$B$100,0) returns the position of E2 within column B. The 0 requests an exact match. INDEX then returns the value at that position in column A. If MATCH finds nothing, the whole formula returns #N/A, and you can wrap it in IFNA as before.
This approach also survives column insertions better than a hard-coded column number such as the 2 in VLOOKUP.
Using XLOOKUP's built-in fallback
In Excel versions that include XLOOKUP, you can supply the "not found" result as an argument, with no wrapper needed.
=XLOOKUP(E2,$A$2:$A$100,$B$2:$B$100,"Not found")XLOOKUP defaults to an exact match and can look in either direction. The fourth argument applies only to missing matches, so, like IFNA, it does not hide other errors.
When #N/A comes from somewhere else
A lookup is not the only source of #N/A. Two other cases are worth knowing.
- Typed on purpose. The
NA()function returns#N/Adeliberately. Charts skip#N/Apoints instead of plotting them as zero, so people use it to leave gaps in a line chart. - Passed along from another cell. If a formula refers to a cell that already contains
#N/A, the result is also#N/A. A single missing lookup can spread through a chain of calculations such asSUMor+.
In the second case, fix the source cell. Use Trace Precedents (covered in a later chapter) to follow the arrows back to the original lookup.
If you need totals that skip lookup misses, you have two options. AGGREGATE can ignore errors in its range. Or you can make the lookup return an empty string with IFNA, and use a function such as SUM, which ignores text in a range.
=AGGREGATE(9,6,C2:C100)In this formula, 9 selects SUM and 6 tells Excel to ignore error values.
Prevent first, mask second
Use this order of preference:
- Fix the data so that values that should match do match: clean spaces, convert text numbers, and add missing rows.
- Fix the formula: exact match mode, absolute references, and a range that covers all the data.
- Handle genuine misses with
IFNAor theXLOOKUPfallback, and choose wording that tells the reader what happened, such as "Not found" or "Not in price list."
Do not use IFNA to cover up a mismatch you have not investigated. If many rows show "Not found" and you expected matches, the cause is almost certainly in the data.
Exercise
A lookup in F2 is =VLOOKUP(E2,$A$2:$B$100,2,FALSE). E2 shows 4021 and the table clearly contains 4021 in column A, but F2 returns #N/A. The numbers in column A are left-aligned and have small green triangles. What is the most likely cause, and how can you fix it without changing the table?
Show answer
The table values are numbers stored as text, while E2 is a real number, so Excel treats them as different. Without changing the table, convert the lookup value to text: =VLOOKUP(E2&"",$A$2:$B$100,2,FALSE). A cleaner long-term fix is to convert column A to real numbers (for example with Error Checking's "Convert to Number" option, or VALUE) so every lookup works.
Exercise
You wrap a lookup in IFERROR with the message "Not found." Later, a colleague deletes the price column, and the sheet still shows "Not found" for every product. Which function would have shown the problem, and why?
Show answer
IFNA would have shown it. Deleting the column makes the lookup return #REF!, not #N/A. IFNA replaces only #N/A, so the #REF! would have stayed visible. IFERROR replaces every error type, so it hid the broken reference.
Exercise
Column A holds employee names and column B holds employee IDs. You need the name for the ID in E2, but VLOOKUP cannot search column B and return column A. Write a formula that returns the name and shows "No such ID" only when the ID is missing.
Show answer
=IFNA(INDEX($A$2:$A$100,MATCH(E2,$B$2:$B$100,0)),"No such ID"). MATCH finds the row of the ID in column B using exact match, INDEX returns the name from the same row of column A, and IFNA replaces only the #N/A that appears when the ID is not found.