Excel course · Lesson 16 of 34
Lookup guide: VLOOKUP vs INDEX/MATCH vs XLOOKUP
Learn when and how to use VLOOKUP, INDEX with MATCH and XLOOKUP: exact and approximate matches, left lookups, two-way lookups and handling #N/A.
Looking up a value in a table is one of the most common jobs in Excel: find the price for a product code, the department for an employee ID, the tax rate for an income band. Excel offers several ways to do it. This lesson compares the three you will meet most often, VLOOKUP, INDEX with MATCH, and XLOOKUP, shows exactly how each one works, and tells you which to use in which situation.
The example table
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Code | Product | Category | Price | Stock |
| 2 | P-101 | Keyboard | Accessories | 25 | 140 |
| 3 | P-102 | Mouse | Accessories | 12 | 310 |
| 4 | P-103 | Monitor 24" | Displays | 189 | 42 |
| 5 | P-104 | Laptop 14" | Computers | 950 | 18 |
| 6 | P-105 | Docking station | Accessories | 145 | 0 |
A product list in A1:E6. Codes in column A are unique.
The question for every example: what is the price of product P-103? The answer must be 189.
VLOOKUP
VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Code | Product | Category | Price | Stock | ||
| 2 | P-101 | Keyboard | Accessories | 25 | 140 | 189 | |
| 3 | P-102 | Mouse | Accessories | 12 | 310 | ||
| 4 | P-103 | Monitor 24" | Displays | 189 | 42 | ||
| 5 | P-104 | Laptop 14" | Computers | 950 | 18 | ||
| 6 | P-105 | Docking station | Accessories | 145 | 0 |
Find P-103 in the first column of A2:E6 and return the 4th column.
Result: 189
lookup_value: what you are looking for, here"P-103"(normally a cell reference such asG1).table_array: the whole table. VLOOKUP always searches the first column of this range.col_index_num: which column of the range to return, counted from the left. Price is the 4th column of A:E.range_lookup:FALSE(or 0) for an exact match. Always type FALSE for codes, names and IDs.
VLOOKUP's weaknesses
- It can only look to the right. You cannot find a product name and return the code in column A.
- The column number is hard-coded. Insert a column inside the table and
4now points to Category instead of Price, silently. - It returns only the first match, and only from the top.
=VLOOKUP(G1, A2:E6, MATCH("Price", A1:E1, 0), FALSE). Now the formula finds the Price column by its header.INDEX and MATCH
MATCH finds the position of a value in a single row or column. INDEX returns the value at a given position. Combined, they perform a lookup in any direction and work in every Excel version.
=MATCH("P-103", A2:A6, 0) → 3 (P-103 is the 3rd item)
=INDEX(D2:D6, 3) → 189 (3rd item of the price column)
=INDEX(D2:D6, MATCH("P-103", A2:A6, 0))| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Code | Product | Category | Price | Stock | ||
| 2 | P-101 | Keyboard | Accessories | 25 | 140 | 189 | |
| 3 | P-102 | Mouse | Accessories | 12 | 310 | ||
| 4 | P-103 | Monitor 24" | Displays | 189 | 42 | ||
| 5 | P-104 | Laptop 14" | Computers | 950 | 18 | ||
| 6 | P-105 | Docking station | Accessories | 145 | 0 |
Result: 189
- The
0in MATCH means exact match. Always include it for codes and names. - Because the return column (
D2:D6) and the search column (A2:A6) are separate ranges, inserting columns does not break the formula. - Left lookup is easy:
=INDEX(A2:A6, MATCH("Mouse", B2:B6, 0))returnsP-102.
Two-way lookup with INDEX and two MATCHes
Give INDEX a whole table plus a row number and a column number to look up in both directions. To find the stock of the Laptop by product name and column header:
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Code | Product | Category | Price | Stock | ||
| 2 | P-101 | Keyboard | Accessories | 25 | 140 | 18 | |
| 3 | P-102 | Mouse | Accessories | 12 | 310 | ||
| 4 | P-103 | Monitor 24" | Displays | 189 | 42 | ||
| 5 | P-104 | Laptop 14" | Computers | 950 | 18 | ||
| 6 | P-105 | Docking station | Accessories | 145 | 0 |
Row from the product name, column from the header text. (The doubled quote is how a " character is written inside a text string.)
Result: 18
XLOOKUP
XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Code | Product | Category | Price | Stock | ||
| 2 | P-101 | Keyboard | Accessories | 25 | 140 | 189 | |
| 3 | P-102 | Mouse | Accessories | 12 | 310 | ||
| 4 | P-103 | Monitor 24" | Displays | 189 | 42 | ||
| 5 | P-104 | Laptop 14" | Computers | 950 | 18 | ||
| 6 | P-105 | Docking station | Accessories | 145 | 0 |
Result: 189
XLOOKUP was designed to replace both VLOOKUP and INDEX/MATCH. It defaults to an exact match, looks left or right, has a built-in 'not found' value and can return several columns at once.
- Not found:
=XLOOKUP(G1, A2:A6, D2:D6, "Unknown code")shows a message instead of#N/A. - Left lookup:
=XLOOKUP("Mouse", B2:B6, A2:A6)returnsP-102. - Several columns:
=XLOOKUP("P-104", A2:A6, B2:E6)spills four cells:Laptop 14",Computers,950,18. - Last match:
search_mode-1searches from the bottom, perfect for 'latest price' in a log sorted by date. - Wildcards:
match_mode2allows*and?:=XLOOKUP("Dock*", B2:B6, D2:D6, , 2)returns 145.
#NAME?. If your file is shared with people on older versions, use INDEX/MATCH.Approximate match: bands and tiers
Sometimes you do not want an exact match. A commission rate depends on which band a sales figure falls into. For this, put the lower limit of each band in a column sorted ascending and use approximate match.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | From | Rate | ||
| 2 | 0 | 0.02 | 6% | |
| 3 | 10000 | 0.04 | ||
| 4 | 25000 | 0.06 | ||
| 5 | 50000 | 0.08 |
31,500 is not in the list, so match_mode -1 returns the next smaller item, 25,000 → 6% (B formatted as %).
Result: 6%
| Function | Approximate-match version | Requirement |
|---|---|---|
| VLOOKUP | =VLOOKUP(31500, A2:B5, 2, TRUE) | First column sorted ascending |
| INDEX/MATCH | =INDEX(B2:B5, MATCH(31500, A2:A5, 1)) | Sorted ascending |
| XLOOKUP | =XLOOKUP(31500, A2:A5, B2:B5, , -1) | Works even if not sorted |
Dealing with #N/A
#N/A means not found. Before hiding it, find out why:
- Extra spaces:
"P-103 "with a trailing space does not equal"P-103". Clean with TRIM. - Numbers stored as text: the code
1001as a number does not match"1001"as text. Convert one side, for example=XLOOKUP(G1&"", A2:A6, D2:D6)if the table holds text. - Missing approximate flag: VLOOKUP without FALSE on unsorted data.
- Range not locked: the table range moved when the formula was filled down. Use
$A$2:$E$6or a table reference.
Once you know the misses are genuine, show a friendly value: XLOOKUP's if_not_found argument, or =IFNA(VLOOKUP(G1,$A$2:$E$6,4,FALSE),"Not listed") in older versions. Prefer IFNA over IFERROR, because IFERROR also hides real errors like #REF! or a misspelled function.
Which one should you use?
| Situation | Recommended |
|---|---|
| Microsoft 365 / Excel 2021+ only | XLOOKUP |
| File used in Excel 2019 or older | INDEX/MATCH (or VLOOKUP with FALSE) |
| Return value is left of the search column | XLOOKUP or INDEX/MATCH |
| Two-way lookup (row and column) | INDEX with two MATCHes, or nested XLOOKUP |
| Need all matches, not just the first | FILTER (Dynamic arrays: spill, FILTER, SORT, UNIQUE, SEQUENCE and #) |
| Lookup on several conditions | XLOOKUP with 1, (A=x)*(B=y) or FILTER |
Lookup with two conditions
To find the price where Category is Accessories and Stock is 0, multiply the two tests. Each test returns TRUE/FALSE arrays; multiplying gives 1 only where both are true: =XLOOKUP(1, (C2:C6="Accessories")*(E2:E6=0), D2:D6) returns 145, the docking station. In older versions the equivalent is =INDEX(D2:D6, MATCH(1, (C2:C6="Accessories")*(E2:E6=0), 0)), confirmed with Ctrl+Shift+Enter in Excel 2019 and earlier.
Check yourself
1. What does =VLOOKUP("P-103", A2:E6, 4) risk, compared with the same formula ending in FALSE?
Without FALSE, VLOOKUP assumes sorted data and an approximate match.
2. Which formula can return the code in column A for a product name in column B?
INDEX/MATCH can look left; VLOOKUP cannot.
3. What does =MATCH("P-104", A2:A6, 0) return?
MATCH returns the position: P-104 is the 4th item in A2:A6.
4. In which version does XLOOKUP NOT exist?
XLOOKUP needs Microsoft 365 or Excel 2021 and later.
5. Why is IFNA usually better than IFERROR around a lookup?
IFERROR hides every error, including ones that signal a broken formula.