XLOOKUP and VLOOKUP
Pull matching values from another table with XLOOKUP and VLOOKUP, use approximate match for tiers, and diagnose and handle #N/A errors.
Welcome back!
Step 1 of 13Learn
Stop copying values by hand
Elena has an orders sheet with product IDs and a separate price list with 600 products. For every order she scrolls the price list, finds the ID and types the price. It takes hours and she makes mistakes. A lookup function does it instantly and correctly: find this value in that list, and bring back the matching item.
The modern function is XLOOKUP (Microsoft 365, Excel 2021 and later, Excel for the web, and Google Sheets):
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found])
With product IDs in Prices!A2:A601 and prices in Prices!C2:C601, the price for the ID in B2 is:
=XLOOKUP(B2, Prices!$A$2:$A$601, Prices!$C$2:$C$601, "Not found")
Read it as a sentence: look for B2 in the ID column and return the value from the price column in the same row; if it isn't there, say "Not found".
XLOOKUP looks for an exact match by default, which is what you want for IDs, emails and codes. The return column can be anywhere: to the right, to the left, even on another sheet. The ranges are locked with $ because the formula will be copied down the orders list. Both arrays must be the same height, or XLOOKUP returns #VALUE!.
Step 2 of 13Diagram
What XLOOKUP does for each order
Tap a shape with to see more.
- Take the ID in B2
The lookup_value.
- Search Prices!A:A
The lookup_array: the column of IDs.
- Find the matching row
Exact match by default.
- Return from Prices!C:C
The return_array: same row, price column.
Step 3 of 13Learn
VLOOKUP, the function in every old file
Before XLOOKUP, everyone used VLOOKUP, and you'll meet it in shared workbooks for years:
=VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
=VLOOKUP(B2, Prices!$A$2:$D$601, 3, FALSE)
- It searches the first (leftmost) column of the table for B2.
- It returns the value from the 3rd column of the table (column C here; the count starts at the table's first column, not at column A of the sheet).
- FALSE means exact match.
VLOOKUP has three traps:
- The forgotten FALSE. If you omit the fourth argument, VLOOKUP uses approximate match, which assumes the first column is sorted. On an unsorted ID list it can return a price from the wrong product without any error. Always type FALSE (or 0) for exact lookups.
- It can't look left. The lookup column must be the first column of the table. If IDs are in column D and names in column B, VLOOKUP cannot do it.
- Hard-coded column numbers. Insert a new column inside the table and the 3 now points at a different column, silently returning the wrong data.
XLOOKUP fixes all three, which is why you should prefer it whenever your version has it. The older workaround, INDEX and MATCH, also fixes them: =INDEX(Prices!C2:C601, MATCH(B2, Prices!A2:A601, 0)).
Step 4 of 13Practice · Choose one
=VLOOKUP("P-104", A2:D50, 3, FALSE) finds P-104 in row 12. Which cell does it return?
Step 5 of 13Compare
Three ways to look things up
| Aspect | XLOOKUP | VLOOKUP | INDEX + MATCH |
|---|---|---|---|
| Default match | Exact | Approximate (must add FALSE) | Set by MATCH (use 0 for exact) |
| Can return a column to the left | Yes | No | Yes |
| Survives inserted columns | Yes | No, the column number goes stale | Yes |
| Built-in "not found" message | Yes, 4th argument | No, wrap in IFNA | No, wrap in IFNA |
| Availability | Microsoft 365, Excel 2021+, web, Google Sheets | Every version | Every version |
Step 6 of 13Learn
Why lookups return #N/A, and what to do
#N/A means "the value you asked for is not in the lookup column". Sometimes that is genuinely true: the product was discontinued or the ID was mistyped. Often, though, the value looks present but isn't an exact match. The usual causes:
- Extra spaces: "P-104 " with a trailing space is not "P-104". Clean with TRIM.
- Numbers versus text: an ID stored as the number 104 will not match the text "104". Check alignment; convert with VALUE or by multiplying by 1, or turn numbers into text with TEXT.
- Typos and lookalike characters: a letter O instead of zero, or a dash pasted from a web page that is a different character.
- Wrong range: the lookup range doesn't cover all rows, often because new rows were added below a fixed range.
- Forgotten $ signs: the range shifted when the formula was copied down, so lower rows search a shrinking list.
Once you know the remaining #N/A values are legitimate, display something friendlier. XLOOKUP has a built-in fourth argument. For VLOOKUP, wrap it: =IFNA(VLOOKUP(B2, Prices!$A$2:$D$601, 3, FALSE), "Not found").
Be careful with IFERROR: it hides every error, including #REF! and #VALUE! from broken formulas. IFNA hides only "not found", which is usually what you mean. Never blanket-hide errors before investigating them; a hidden error can turn into a wrong invoice.
Step 7 of 13Practice · Diagram
Diagnosing #N/A
"P-104 " with a trailing space fails to match "P-104". Tap the cause.
Tap the shape that answers the question, then press Check.
- #N/A
- Really not in the list
Discontinued or mistyped. Show a friendly message with IFNA or XLOOKUP's 4th argument.
- Looks present, isn't a match
- Searching the wrong rows
- Extra spaces
Clean with TRIM.
- Number vs text
104 is not "104"; convert with VALUE or TEXT.
- Lookalike characters
Letter O vs zero, odd dashes from web pages.
- Range too short
New rows added below a fixed range.
- Missing $ signs
The range shifts as the formula is copied down.
Step 8 of 13Practice · Select all that apply
A lookup returns #N/A for an ID you can clearly see in the price list. Which of these could explain it? Select all that apply.
Select all that apply.
Step 9 of 13Learn
Approximate match: tiers and brackets
Exact match is for IDs. Approximate match is for tiers: discount levels, shipping bands, tax brackets, grade boundaries. You list the lower edge of each tier:
| Order total from | Discount |
|---|---|
| 0 | 0% |
| 100 | 5% |
| 500 | 10% |
| 1000 | 15% |
For an order of $640 you want 10%: the largest threshold that is not above 640.
- XLOOKUP:
=XLOOKUP(B2, $F$2:$F$5, $G$2:$G$5, , -1). The 5th argument, match_mode -1, means "exact match, or the next smaller item". - VLOOKUP:
=VLOOKUP(B2, $F$2:$G$5, 2, TRUE). With TRUE, the first column must be sorted ascending.
This is cleaner than a nested IF: when the business adds a 2,500 tier, you add a row to the table instead of rewriting formulas.
Test the edges. An order of exactly $500 should get 10% (500 is the lower edge of that tier). An order of $499.99 should get 5%. And decide what happens below the first threshold: if your table started at 100, an order of $60 would return #N/A, so tier tables usually begin at 0.
Step 10 of 13Practice · Diagram
Discount tiers on a number line
Which order gets the 10% discount?
Tap the shape that answers the question, then press Check.
- Order $80
$80
- Order $640
$640
- Order $1,200
$1,200
Step 11 of 13Practice · Work it out
Using the discount table from the lesson (0 → 0%, 100 → 5%, 500 → 10%, 1000 → 15%), what discount does an approximate-match lookup return for an order of $999? Enter the percentage.
Step 12 of 13Practice · What would you do?
What would you do?
Ken's formula =VLOOKUP(B2, Products!A2:C900, 3) returns prices for every order, with no errors. A customer then points out she was charged for a different product. The product list is in the order items were added, not sorted. What went wrong?
Step 13 of 13Practice · Fill in the blanks
Fill in the blanks
Product IDs are in A2:A100 and prices in C2:C100. To return the price for the ID in F2, or the text "Not found", write =XLOOKUP(F2, A2:A100, , "Not found").
Lesson complete!