Sub topic 4
Where VLOOKUP falls short
This chapter assumes you can enter formulas in Google Sheets, read ranges such as A2:C100, anchor ranges with $, and refer to another sheet. It also assumes you have written a basic VLOOKUP with FALSE as the last argument. Here you will learn the specific ways VLOOKUP limits you, how each limit shows up in a real sheet, and which workarounds exist. The next chapter introduces XLOOKUP, which removes most of these limits.
VLOOKUP is still correct and widely used. Its problems are design constraints, and each one matches a task you will eventually hit.
The sample data
The examples use a product list in A1:C100, with headers in row 1:
| Column | Header | Example value |
|---|---|---|
| A | Product ID | P-102 |
| B | Name | Widget |
| C | Price | 4.50 |
The key you look up is in E2.
Limit 1: The key must be in the first column
VLOOKUP always searches the leftmost column of the range you give it. It can only return values from that column or columns to its right.
Suppose you have a product name in E2 and want its ID. The ID is in column A, which is left of the name in column B. This formula cannot work:
=VLOOKUP(E2, A2:C100, 1, FALSE)It searches column A for a name, finds nothing, and returns #N/A. Changing the range to start at column B searches the right column, but then the ID is outside the range:
=VLOOKUP(E2, B2:C100, 1, FALSE)Index 1 here returns the name you already typed in, not the ID.
You have three ways to get around this:
- Rearrange the source data so the key column comes first. This is not always possible, especially when the data comes from an import or belongs to someone else.
- Use
INDEXandMATCH, which accept separate ranges for searching and returning:
=INDEX(A2:A100, MATCH(E2, B2:B100, 0))- Use
XLOOKUP, which treats the search range and the result range as independent arguments:
=XLOOKUP(E2, B2:B100, A2:A100, "Not found")Limit 2: The column index is a hard-coded number
The third argument of VLOOKUP counts columns from the left edge of the range. It is a plain number, not a reference to a column. Sheets cannot track what that number means when the layout changes.
Take this formula, which returns the price:
=VLOOKUP(E2, A2:C100, 3, FALSE)Now someone inserts a new column, such as Category, between Name and Price. Sheets expands the range to A2:D100 because the insertion falls inside it. The index stays 3, which now points to the new Category column. The formula still runs and shows a plausible value, but it is the wrong one.
Two other index problems produce visible errors instead:
- An index larger than the number of columns in the range returns
#REF!with the message "VLOOKUP evaluates to an out of bounds range". - An index below 1 returns
#VALUE!.
The visible errors are easy to catch. The silent shift is the dangerous case, because the numbers look reasonable and nobody notices.
You can make the index self-adjusting by computing it from the header row with MATCH:
=VLOOKUP(E2, A2:D100, MATCH("Price", A1:D1, 0), FALSE)MATCH("Price", A1:D1, 0) returns the position of the "Price" header inside the range. If a column is inserted, the position updates when the formula is recalculated. This works but makes the formula longer. XLOOKUP avoids the problem by returning a whole column reference such as C2:C100, which Sheets adjusts like any other reference.
=XLOOKUP(E2, A2:A100, C2:C100, "Not found")Limit 3: Approximate match is the default
The fourth argument of VLOOKUP, called is_sorted, is optional. When you leave it out, Sheets treats it as TRUE, which means approximate match. This formula looks like an exact lookup but is not:
=VLOOKUP(E2, A2:C100, 3)With approximate match, VLOOKUP assumes the first column is sorted ascending. It uses a binary search, which jumps through the list and narrows in on the position. It returns the row with the largest value that is less than or equal to your key.
If the data is not sorted, the jumps land in the wrong places. The result can be a wrong row, or a #N/A for a key that exists in the data. The formula gives no sign that anything went wrong.
Approximate match has one legitimate use: a tier table. If F2:G6 holds sorted thresholds and the label for each, approximate match finds the right tier:
=VLOOKUP(B2, $F$2:$G$6, 2, TRUE)Here the sorting requirement is a feature. For ID or name lookups, use FALSE.
Limit 4: It can only return the first match
If the key appears in several rows, VLOOKUP returns the value from the first one, reading from the top. There is no argument to change the direction.
This matters for logs and history tables. If a price list adds a new row each time a price changes, the current price is the last row for each product. VLOOKUP returns the oldest price. To get the most recent, you must sort the data in reverse or use another function. XLOOKUP takes a search mode argument for this:
=XLOOKUP(E2, A2:A100, C2:C100, "Not found", 0, -1)The -1 makes it search from the bottom up. The next chapters cover this in detail.
Limit 5: It returns one column per formula
A VLOOKUP returns a single value from a single column. To pull the name, price, and stock level for one product, you write three formulas that differ only in their index:
=VLOOKUP($E2, $A$2:$D$100, 2, FALSE)
=VLOOKUP($E2, $A$2:$D$100, 3, FALSE)
=VLOOKUP($E2, $A$2:$D$100, 4, FALSE)Each one repeats the search. That is acceptable for a few cells and slow for large sheets with thousands of lookups. It also gives you several indexes to maintain, which multiplies the problem from Limit 2. XLOOKUP accepts a multi-column result range and spills all the values from one formula:
=XLOOKUP(E2, A2:A100, B2:D100)Limit 6: Missing keys are not handled
When the key is not found, VLOOKUP returns #N/A. There is no argument for a fallback. You wrap the formula in IFNA:
=IFNA(VLOOKUP(E2, A2:C100, 3, FALSE), "Not found")Use IFNA and not IFERROR here. IFERROR hides every error, including #REF! from a bad index, which would make the formula report "Not found" for a real bug. IFNA catches only #N/A, so structural mistakes stay visible.
How the limits combine
The following diagram shows how the limits decide whether VLOOKUP fits a task.
Other behavior to know
These points are smaller but cause confusion:
- Case is ignored.
VLOOKUPtreats "p-102" and "P-102" as the same key. If your data has keys that differ only by case, it returns whichever comes first. - Types must match. The text "102" and the number 102 are different values. A key stored as text will not match a number, which causes
#N/A. The troubleshooting chapter covers this. - Hidden spaces break matches. A trailing space makes "P-102 " a different key from "P-102". Wrapping the key in
TRIMhelps:
=VLOOKUP(TRIM(E2), A2:C100, 3, FALSE)- Whole-column ranges cost more.
A:Cforces Sheets to consider every row, including empty ones. A bounded range likeA2:C100is faster, but it must be extended when the data grows.
Reading the symptoms
When a lookup misbehaves, the symptom usually points at the limit:
| Symptom | Likely limit |
|---|---|
| `#N/A` when searching for a value left of the result | Key not in the first column |
| Right formula, wrong number after a column was inserted | Hard-coded column index |
| Wrong or missing results on unsorted data, no error | Approximate match default |
| Old value returned from a history table | First match only |
| `#REF!` with "out of bounds range" | Index larger than the range width |
| `#N/A` on a key that visibly exists | Spaces or text-versus-number mismatch |
Exercises
Exercise
A sheet has Name in column B and Product ID in column A. You write =VLOOKUP("Widget", A2:C100, 1, FALSE) to find the ID of the product named Widget, and it returns #N/A. Why does it fail, and what formula fixes it without moving any columns?
Show answer
VLOOKUP searches only the first column of its range, which is column A (the IDs), so it looks for the text "Widget" among IDs and finds nothing. Use a function that takes separate ranges, for example =XLOOKUP("Widget", B2:B100, A2:A100, "Not found") or =INDEX(A2:A100, MATCH("Widget", B2:B100, 0)).
Exercise
Your formula is =VLOOKUP(E2, A2:C100, 3, FALSE) and returns prices correctly. A coworker inserts a Category column between Name and Price. The formula still shows a value and no error. What happens, and how can you make the formula survive this change?
Show answer
The range expands to A2:D100 but the index stays 3, so the formula now returns Category instead of Price, with no error. Compute the index from the header, for example =VLOOKUP(E2, A2:D100, MATCH("Price", A1:D1, 0), FALSE), or use XLOOKUP with a result range reference such as C2:C100 (which becomes D2:D100 automatically).
Exercise
Why is IFNA a better wrapper than IFERROR for a VLOOKUP that should show "Not found" for missing keys?
Show answer
IFNA only replaces #N/A, which is what a missing key produces. IFERROR also hides other errors such as #REF! from an out-of-range column index, so a real bug would display as "Not found".