VLOOKUP & XLOOKUP

Excel · Lesson 12 of 30 8 min read Updated

A lookup finds a value in one table and brings back related information. Type a product code and get its price; type a roll number and get the student's name; type a sales amount and get the commission rate from a slab table. Lookups connect separate lists, and they are among the most-used formulas in any office.

In this lesson you will learn XLOOKUP, the modern lookup function, first. Then you will learn VLOOKUP, which you will still find in millions of existing workbooks, and see exactly why XLOOKUP replaced it.

The sample sheet

A general store in Rohtak keeps its product list in A1:E6 and types a product code into H2 to fetch details:

ABCDE
1CodeProductCategoryPrice (₹)Stock
2P101Basmati rice 5 kgGrocery64940
3P102Toor dal 1 kgGrocery16585
4P103Sunflower oil 1 LGrocery18960
5P104Steel tiffin boxKitchen49912
6P105Pressure cooker 5 LKitchen21507

XLOOKUP: the modern way

Excel formula
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

The first three arguments are all you need most of the time: what to find, where to find it, and what to bring back. With P104 in H2:

Excel formula
=XLOOKUP(H2, A2:A6, D2:D6)
Output
499

Excel looked for P104 in A2:A6, found it in the 4th position, and returned the 4th value of D2:D6. XLOOKUP is available in Microsoft 365, Excel 2021 and later, Excel for the web, and Google Sheets.

When the value is not found

By default, a missing code returns #N/A. The fourth argument replaces that with your own message:

Excel formula
=XLOOKUP(H2, A2:A6, D2:D6, "Code not found")

For a code such as P109, the cell shows "Code not found" instead of an error.

Looking to the left

The return column can be anywhere, including to the left of the lookup column. To find the code of a product by its name:

Excel formula
=XLOOKUP("Steel tiffin box", B2:B6, A2:A6)
Output
P104

Returning several columns at once

If the return array is several columns wide, the answer spills into neighbouring cells. One formula in I2 fills three cells:

Excel formula
=XLOOKUP(H2, A2:A6, B2:D6)
IJK
2Steel tiffin boxKitchen499

Slab rates with approximate match

Many Indian business rules are slabs: commission, discounts, delivery charges, tax brackets. A sales team earns commission by monthly sales. This made-up slab table sits in M1:N5:

MN
1Sales from (₹)Commission
200%
3500002%
41000003.5%
52000005%

Each row says "from this amount upwards". There is no exact match for 84000, so ask for the exact match or the next smaller item with match_mode -1:

Excel formula
=XLOOKUP(84000, M2:M5, N2:N5, , -1)
Output
0.02

84000 falls between 50000 and 100000, so the smaller boundary, 50000, wins and the rate is 2%. For 126000 the result is 3.5%, and for 250000 it is 5%. The empty argument between the commas skips if_not_found. Match mode 1 does the opposite (exact or next larger), and 2 allows the * and ? wildcards.

The sixth argument, search_mode, sets the direction: -1 searches from the bottom up. In a price-history list where new rows are added at the bottom, =XLOOKUP(H2, A2:A50, D2:D50, , 0, -1) returns the latest price for a code.

VLOOKUP: the older function

VLOOKUP ("vertical lookup") was the standard lookup for decades, so you will meet it in almost every office workbook.

Excel formula
=VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])

It searches the first column of the table and returns the value from the column number you give. The price of P104 is in the 4th column of A2:E6:

Excel formula
=VLOOKUP(H2, A2:E6, 4, FALSE)
Output
499

That FALSE at the end is essential. It asks for an exact match.

Why XLOOKUP replaced VLOOKUP

Problem with VLOOKUPHow XLOOKUP handles it
Defaults to approximate matchDefaults to exact match
Cannot return a column to the left of the lookup columnReturn array can be anywhere
Column number (4) breaks when a column is insertedUses a range, which adjusts automatically
Needs IFERROR around it for a friendly messageHas a built-in if_not_found argument
Returns one column at a timeCan return several columns at once

VLOOKUP is still fine for the slab-table job when its first column is sorted: =VLOOKUP(84000, M2:N5, 2, TRUE) returns 2%. Its sideways twin HLOOKUP searches a top row instead of a first column. Use XLOOKUP for new work whenever everyone who opens the file has Excel 2021 or later; use VLOOKUP or INDEX & MATCH if the file must work in Excel 2019 or older.

Looking up from another sheet

The product list usually lives on its own sheet. Point the ranges at that sheet, and lock them with $ so they do not move when you copy the formula down an order list:

Excel formula
=XLOOKUP(A2, Products!$A$2:$A$6, Products!$D$2:$D$6, 0)

Here a missing code returns 0 so that the bill total still works. In Excel Tables you will replace these ranges with names that grow by themselves.

Common mistakes

  • Leaving out FALSE in VLOOKUP. You get wrong answers instead of errors. Always add it for exact matches.
  • Extra spaces. "P104 " with a trailing space does not match "P104". Clean the data with TRIM.
  • Numbers versus text. A code typed as the number 101 does not match the text "101". Make both columns the same type.
  • Ranges of different sizes in XLOOKUP. A2:A6 and D2:D7 give #VALUE!.
  • Unsorted slab tables. Approximate-match lookups expect the boundaries in ascending order with VLOOKUP; keep slab tables sorted anyway, for readability.

Key points

  • XLOOKUP(what, where, return) finds a value and returns the matching item; it defaults to exact match.
  • Its fourth argument replaces #N/A with your message; match mode -1 handles slab tables.
  • XLOOKUP can look left, return several columns, and search from the bottom up.
  • VLOOKUP(value, table, column_number, FALSE) is the older way; never omit FALSE for exact lookups.
  • Use XLOOKUP in Excel 2021, 2024, Microsoft 365 and Google Sheets; use VLOOKUP or INDEX/MATCH for older versions.

Exercise

Using the product sheet, build a small order form. In H5:H7 type the codes P102, P105 and P109, and in I5:I7 the quantities 3, 1 and 2. In J5, write one formula (to copy down) that returns the price, showing 0 for unknown codes. In K5 calculate the line amount, and in K8 the bill total. Then write the same price formula with VLOOKUP for a colleague who has Excel 2019.

Show solution
Excel formula
=XLOOKUP(H5, $A$2:$A$6, $D$2:$D$6, 0)
=I5*J5
=SUM(K5:K7)
Output
J5: 165   K5: 495
J6: 2150  K6: 2150
J7: 0     K7: 0
K8: 2645

For Excel 2019, VLOOKUP has no if_not_found argument, so wrap it in IFERROR: =IFERROR(VLOOKUP(H5, $A$2:$E$6, 4, FALSE), 0). Both versions use $ so the product ranges stay fixed when copied down.

Quick Quiz

1. What does XLOOKUP do by default when the value is not in the list?

2. Why should you write FALSE as the last argument of VLOOKUP?

3. Which XLOOKUP match_mode finds the right row in a "from this amount upwards" slab table?

4. A VLOOKUP uses column number 4. What happens if someone inserts a new column inside the table?

Learn Excel with a mentor

Free lessons get you started. Our Excel & Office Skills training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call