Comprehensive Guide to Using XLOOKUP in Excel
The XLOOKUP
function is a versatile tool in Excel designed to search a range or array, find the right value, and return a corresponding value from another range or array. It is part of the newer Excel functions introduced to simplify and improve upon older functions like VLOOKUP
, HLOOKUP
, and INDEX-MATCH
. XLOOKUP
is available in Excel for Microsoft 365, Excel 2019, and later versions.
Syntax of XLOOKUP
The syntax for XLOOKUP
is as follows:
XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
- lookup_value: The value you are searching for in the lookup array.
- lookup_array: The array or range of cells containing the value to look for.
- return_array: The array or range of cells from which to return a value.
- if_not_found (optional): The value to return if
lookup_value
is not found. This is optional and defaults to#N/A
if omitted. - match_mode (optional): Determines the type of match:
0
- Exact match. Returns#N/A
if no exact match is found (default).-1
- Returns the next smaller item if no exact match is found.1
- Returns the next larger item if no exact match is found.2
- Allows using wildcards (?
for one character,*
for any sequence of characters) inlookup_value
.
- search_mode (optional): Specifies the search order:
1
- Search from first to last (default).-1
- Search from last to first.2
- Binary search (must be sorted in ascending order).-2
- Binary search (must be sorted in descending order).
Practical Examples of Using XLOOKUP
Example 1: Basic Exact Match
Imagine you have a list of products and their prices in columns A and B, respectively. You want to find the price of a product named "Widget".
=XLOOKUP("Widget", A2:A100, B2:B100)
This formula searches for "Widget" in cells A2 through A100 and returns the corresponding price from cells B2 through B100.
Example 2: Handling Non-Found Items
If you want to return a custom message instead of an error when the product is not found:
=XLOOKUP("Gadget", A2:A100, B2:B100, "Product not found")
This formula looks for "Gadget" and returns "Product not found" if it does not exist in the range.
Example 3: Using Wildcards for Partial Matches
Suppose you're looking for any product that contains the substring "Box" in its name:
=XLOOKUP("*Box*", A2:A100, B2:B100, "No matching product", 2)
This setup uses wildcards to find products with "Box" anywhere in the name and returns "No matching product" if no such products are found.
Example 4: Searching from Last to First
To find the last occurrence of "Widget" in the list when multiple entries might exist:
=XLOOKUP("Widget", A2:A100, B2:B100, "Product not found", 0, -1)
This command searches backward, starting from the last cell towards the first.
Benefits of Using XLOOKUP
- Simplicity: Easier to write and read compared to its predecessors.
- Flexibility: Capable of returning arrays and handling different types of searches more gracefully.
- Powerful Error Handling: Provides options for custom responses when no matches are found.
XLOOKUP
provides a significant improvement over traditional lookup functions in Excel, offering greater flexibility and accuracy in finding and returning data. Its introduction simplifies complex lookup tasks and enhances productivity in handling Excel datasets.
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.
Comments