XLOOKUP
Search a range or array for a value and return the corresponding result from another range.
Spreadsheet editor
Spreadsheet editor
Syntax
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
Returns: Varies Arguments
| Argument | Required | Description |
|---|---|---|
| lookup_value | Yes | The value to search for in the lookup_array. |
| lookup_array | Yes | The range or array to search for the lookup_value. |
| return_array | Yes | The range or array from which to return the result. |
| if_not_found | No | The value to return if no match is found. Defaults to #N/A if omitted. |
| match_mode | No | The type of match to perform. 0 for exact match (default), -1 for exact or next smaller, 1 for exact or next larger, 2 for wildcard match. |
| search_mode | No | How to search the lookup_array. 1 searches first to last (default), -1 searches last to first, 2 uses binary search on ascending data, -2 uses binary search on descending data. |
About
Use XLOOKUP when you need to pull data from a table based on a match. The optional if_not_found argument replaces the default #N/A error with a custom message or value. The match_mode lets you switch between exact, approximate, and wildcard matching. The search_mode controls direction, so you can find the most recent entry in a list by searching from the last row backward.
XLOOKUP replaces most use cases for VLOOKUP and HLOOKUP, and handles many scenarios that previously required combining INDEX with MATCH. If you need the position of a match rather than the value, use XMATCH instead.
Exercises using XLOOKUP
Lookup error handling
BeginnerHandle missing lookups with IFNA for VLOOKUP and the not_found argument in XLOOKUP.
Open exerciseXLOOKUP a course instructor
BeginnerUse XLOOKUP to find which instructor is assigned to each training course from a course catalog.
Open exerciseXLOOKUP with exact match
BeginnerUse XLOOKUP to pull current stock quantities for items on a reorder list.
Open exerciseLook up a product with XLOOKUP
BeginnerUse XLOOKUP to find a product's category from a product catalog.
Open exerciseXLOOKUP left lookup
IntermediateReturn an ID from a column to the left of the lookup value using XLOOKUP.
Open exerciseXLOOKUP with wildcard search
IntermediateUse XLOOKUP with wildcard matching to find a product and price when you only know part of the product name.
Open exerciseXLOOKUP with default
IntermediateLook up product info, returning "Discontinued" if product not found.
Open exerciseReturn multiple columns
AdvancedLook up a customer ID and return name, email, and phone in one formula row.
Open exerciseXLOOKUP multiple criteria
AdvancedFind the price for a specific product in a specific quarter using nested XLOOKUP.
Open exerciseExamples
Handling missing matches with if_not_found
Spreadsheet editor
Returning a value from a column to the left
Spreadsheet editor
Finding the most recent entry with search_mode -1
Spreadsheet editor
Watch out for
Lookup and return arrays must match in size
If lookup_array and return_array have a different number of rows (or columns for horizontal searches), XLOOKUP returns a #VALUE! error.
→ Make sure both arrays span the same number of cells. If your lookup range is A2:A100, your return range should also have 99 rows.
Missing if_not_found lets #N/A spread
Without a fourth argument, a missing match returns #N/A. Any formula that depends on that result also returns an error.
→ Add an if_not_found value as the fourth argument, such as "Not found", 0, or an empty string, to keep your sheet clean when a lookup fails.
Binary search on unsorted data gives wrong results
Using search_mode 2 or -2 (binary search) on unsorted data returns incorrect results without any error message.
→ Only use binary search modes when your lookup_array is sorted in the matching direction. For unsorted data, use the default search_mode 1.
Confusing match_mode with search_mode
match_mode sets how Excel decides if something is a match (exact, approximate, or wildcard). search_mode sets the direction Excel searches. Using the wrong parameter gives unexpected results.
→ Use match_mode when you want approximate or wildcard matching. Use search_mode when you need to search from last to first or use a binary search on sorted data.