Lookups

How to Use XLOOKUP in Excel

How to use XLOOKUP in Excel: the arguments, exact match by default, returning several columns, and which Excel versions support the function.

On this page
  1. Check your version first
  2. The arguments
  3. A basic example
  4. Return several columns
  5. When XLOOKUP is the better choice

XLOOKUP searches one range for a value and returns the matching item from another range of the same size. It replaces VLOOKUP in many cases, but it is not in every version of Excel, so check that first.

Check your version first

XLOOKUP is available in Excel 2021, in Microsoft 365 and in Excel for the web. It is not available in Excel 2019 or earlier. In those versions, a formula that uses XLOOKUP shows #NAME?, which can be confusing if you copied the formula from someone else. For that error, see why does excel show #name error.

The arguments

=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
  • lookup_value is the value you want to find.
  • lookup_array is the range to search.
  • return_array is the range to return a value from. It must be the same size as the lookup array, but it can be on either side of it.
  • if_not_found is optional. It is the text or value to show when nothing matches. Without it, you get #N/A.
  • match_mode is optional. 0 is an exact match and is the default. -1 means exact or the next smaller item, 1 means exact or the next larger item, and 2 allows wildcards such as * and ?.
  • search_mode is optional. 1 searches from the first item down, which is the default. -1 searches from the last item up.

A basic example

Suppose product codes are in column A of the Orders sheet, and the price list has codes in column A and prices in column C of a sheet named Prices. To get the price for the code in A2:

=XLOOKUP(A2, Prices!$A$2:$A$100, Prices!$C$2:$C$100)

There is no column number to count and no FALSE to type, because XLOOKUP matches exactly by default. The ranges point at the columns themselves rather than at a column number, so the formula still lines up if you insert a column into the price list.

If the list contains the same code more than once, XLOOKUP returns the first match. To get the last one instead, change the search mode. The two empty arguments skip if_not_found and match_mode:

=XLOOKUP(A2, Prices!$A$2:$A$100, Prices!$C$2:$C$100, , , -1)

Return several columns

If the return range covers two columns, XLOOKUP returns both values, spilling them into the cells to the right of the formula. For example, this returns a product name and its price across two cells:

=XLOOKUP(A2, Prices!$A$2:$A$100, Prices!$B$2:$C$100)

The cells that receive the spilled values must be empty. If something is in the way, Excel shows #SPILL!. To clear the problem, see how to fix #spill error in excel.

When XLOOKUP is the better choice

XLOOKUP is easier to read than VLOOKUP, and it can search in either direction. Its default behavior avoids the approximate-match trap that catches many VLOOKUP users. It is worth using wherever your version supports it. If you need the same answer in an older file, INDEX with MATCH does the same job, and how to use index and match in excel explains it.

To show a message or a blank when nothing matches, use the if_not_found argument. For the options, see xlookup return blank if not found.

The complete guide to lookups

How to Look Up Data in Excel
Read the guide

Keep exploring

Guides from other topics

All topics →