Why VLOOKUP returns #N/A, and how to fix it

The shelf has three codes. A100 has 12 on hand. A200 has 48. A300 has 6. VLOOKUP of A200, with FALSE, returns 48.

VLOOKUP
=VLOOKUP(D2,A2:B4,2,FALSE)
=VLOOKUP(D2,A2:B4,2,FALSE)D3
Exact match
ABCD
1SKUOn handLookup
2A10012A200
3A2004848
4A3006
A picture of the shelf. D2 holds A200. FALSE asks for an exact match. Column 2 is the on-hand count, so the result is 48.
=VLOOKUP("A200",A2:B4,2,FALSE)

The fourth argument FALSE is an exact match. Column index 2 counts from the left of the table you passed in. That column is the on-hand count, not column B of the sheet if the table starts somewhere else.

The workbook with a longer stock list is the inventory tracker.

A space makes an exact match fail

The cell looks like A200. LEN of it is 5. The fifth character is a space. An exact VLOOKUP compares every character, so the space is #N/A.

TRIM
=VLOOKUP(TRIM(D2),A2:B4,2,FALSE)
=VLOOKUP(TRIM(D2),A2:B4,2,FALSE)D4
Trailing space
ABCD
1SKUOn handLookup
2A10012A200
3A20048#N/A
4A300648
55
A picture of the same shelf. D2 is the five characters A, 2, 0, 0, and a space. LEN is 5. The exact lookup is #N/A. TRIM drops the space, and the lookup returns 48.

TRIM removes that ordinary space. The cleaned code is A200, and the lookup returns 48.

=VLOOKUP(TRIM(D2),A2:B4,2,FALSE)

TRIM only understands character 32, the ordinary space. A code copied from a web page often ends in character 160, a nonbreaking space. TRIM leaves that character in place, and the exact lookup is still #N/A. The TRIM page shows the same gap on a name. xl.collapse.space turns character 160 into an ordinary space and then trims:

=xl.collapse.space(D2)

Without the name:

=TRIM(SUBSTITUTE(D2,CHAR(160)," "))

The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME?. SUBSTITUTE and TRIM work in older Excel. Saving the name is the same Name Manager step as the LAMBDA how-to.

The code is not in the first column

A400 is not on the shelf. An exact lookup is #N/A. IFNA replaces only that error:

=IFNA(VLOOKUP("A400",A2:B4,2,FALSE),"Not on the shelf")

The result is the words Not on the shelf. A wrong column index is a different error. =VLOOKUP("A200",A2:B4,3,FALSE) is #REF!, because the table has two columns. IFNA leaves #REF! visible. The IFNA page uses the same split on a missing state code, and it says IFERROR would hide the #REF!. IFNA is in Excel 2013 and later. VLOOKUP itself is in every current Excel.

IFNA
=IFNA(VLOOKUP(D2,A2:B4,2,FALSE),"Not on the shelf")
=IFNA(VLOOKUP(D2,A2:B4,2,FALSE),"Not on the shelf")D3
Missing code
ABCD
1SKUOn handLookup
2A10012A400
3A20048Not on the shelf
4A300612
A picture of two misses. A400 is not in column A, so IFNA returns the words. A150 with TRUE is not a miss. It returns 12, the count on A100, because the fourth argument was an approximate match.

The lookup column has to be the leftmost column of the table. If the SKU sits in column B and the count sits in column A, VLOOKUP of A200 looks down column A, finds no A200, and returns #N/A. Move the code to the left, or use XLOOKUP, which can look left.

An approximate match that is not #N/A

Leave the fourth argument off, or pass TRUE, and Excel does an approximate match. The first column has to be sorted ascending. A150 is not a code on the shelf. It sorts after A100 and before A200, so the approximate match returns 12, the count on A100. The cell looks found. FALSE on the same A150 is #N/A.

A code that sorts before the first row is #N/A even with TRUE. A090 is before A100, so that approximate match is #N/A.

The same trap on a state-rate table is XLOOKUP vs VLOOKUP. GA is not in that list. An approximate VLOOKUP returns Florida’s 6.00%. Pass FALSE unless the table is sorted on purpose and the closest smaller value is what you want.


Template for this article

Inventory Tracker with Reorder Points

More from the blog