The shelf has three codes. A100 has 12 on hand. A200 has 48. A300 has 6. VLOOKUP of A200, with FALSE, returns 48.
=VLOOKUP(D2,A2:B4,2,FALSE)| A | B | C | D | |
|---|---|---|---|---|
| 1 | SKU | On hand | Lookup | |
| 2 | A100 | 12 | A200 | |
| 3 | A200 | 48 | 48 | |
| 4 | A300 | 6 |
=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.
=VLOOKUP(TRIM(D2),A2:B4,2,FALSE)| A | B | C | D | |
|---|---|---|---|---|
| 1 | SKU | On hand | Lookup | |
| 2 | A100 | 12 | A200 | |
| 3 | A200 | 48 | #N/A | |
| 4 | A300 | 6 | 48 | |
| 5 | 5 |
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(VLOOKUP(D2,A2:B4,2,FALSE),"Not on the shelf")| A | B | C | D | |
|---|---|---|---|---|
| 1 | SKU | On hand | Lookup | |
| 2 | A100 | 12 | A400 | |
| 3 | A200 | 48 | Not on the shelf | |
| 4 | A300 | 6 | 12 |
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.