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.

Intermediate 20 min read

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

ABCDE
1CodeProductCategoryPriceStock
2P-101KeyboardAccessories25140
3P-102MouseAccessories12310
4P-103Monitor 24"Displays18942
5P-104Laptop 14"Computers95018
6P-105Docking stationAccessories1450

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

Formula
VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
G2fx=VLOOKUP("P-103", A2:E6, 4, FALSE)
ABCDEFG
1CodeProductCategoryPriceStock
2P-101KeyboardAccessories25140189
3P-102MouseAccessories12310
4P-103Monitor 24"Displays18942
5P-104Laptop 14"Computers95018
6P-105Docking stationAccessories1450

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 as G1).
  • 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.
Watch out. If you leave out the last argument, VLOOKUP uses an approximate match. On unsorted data it returns wrong answers without any error. This is the most expensive VLOOKUP mistake in practice.

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 4 now points to Category instead of Price, silently.
  • It returns only the first match, and only from the top.
Tip. If you must use VLOOKUP, make the column number robust with MATCH: =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.

Formula
=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))
Build it in two steps, then nest.
G2fx=INDEX(D2:D6, MATCH("P-103", A2:A6, 0))
ABCDEFG
1CodeProductCategoryPriceStock
2P-101KeyboardAccessories25140189
3P-102MouseAccessories12310
4P-103Monitor 24"Displays18942
5P-104Laptop 14"Computers95018
6P-105Docking stationAccessories1450

Result: 189

  • The 0 in 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)) returns P-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:

G2fx=INDEX(A2:E6, MATCH("Laptop 14""", B2:B6, 0), MATCH("Stock", A1:E1, 0))
ABCDEFG
1CodeProductCategoryPriceStock
2P-101KeyboardAccessories2514018
3P-102MouseAccessories12310
4P-103Monitor 24"Displays18942
5P-104Laptop 14"Computers95018
6P-105Docking stationAccessories1450

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

Formula
XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
G2fx=XLOOKUP("P-103", A2:A6, D2:D6)
ABCDEFG
1CodeProductCategoryPriceStock
2P-101KeyboardAccessories25140189
3P-102MouseAccessories12310
4P-103Monitor 24"Displays18942
5P-104Laptop 14"Computers95018
6P-105Docking stationAccessories1450

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) returns P-102.
  • Several columns: =XLOOKUP("P-104", A2:A6, B2:E6) spills four cells: Laptop 14", Computers, 950, 18.
  • Last match: search_mode -1 searches from the bottom, perfect for 'latest price' in a log sorted by date.
  • Wildcards: match_mode 2 allows * and ?: =XLOOKUP("Dock*", B2:B6, D2:D6, , 2) returns 145.
Note. XLOOKUP is available in Microsoft 365, Excel 2021 and later, Excel for the web and the mobile apps. In Excel 2019 and 2016 it returns #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.

D2fx=XLOOKUP(31500, A2:A5, B2:B5, , -1)
ABCD
1FromRate
200.026%
3100000.04
4250000.06
5500000.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%

FunctionApproximate-match versionRequirement
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 1001 as 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$6 or 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?

SituationRecommended
Microsoft 365 / Excel 2021+ onlyXLOOKUP
File used in Excel 2019 or olderINDEX/MATCH (or VLOOKUP with FALSE)
Return value is left of the search columnXLOOKUP or INDEX/MATCH
Two-way lookup (row and column)INDEX with two MATCHes, or nested XLOOKUP
Need all matches, not just the firstFILTER (Dynamic arrays: spill, FILTER, SORT, UNIQUE, SEQUENCE and #)
Lookup on several conditionsXLOOKUP 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.

Tip. Also have a look at XMATCH, the modern MATCH, and HLOOKUP, VLOOKUP's horizontal twin. XLOOKUP handles horizontal data too: just give it rows instead of columns.

Check yourself

1. What does =VLOOKUP("P-103", A2:E6, 4) risk, compared with the same formula ending in FALSE?

2. Which formula can return the code in column A for a product name in column B?

3. What does =MATCH("P-104", A2:A6, 0) return?

4. In which version does XLOOKUP NOT exist?

5. Why is IFNA usually better than IFERROR around a lookup?

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 20 KB