The XLOOKUP function in Google Sheets allows you to search a range or an array and return a corresponding item from another range or array. It is the modern successor to VLOOKUP and HLOOKUP because it can search in any direction (left, right, up, or down), does not require the search column to be the first column in a range, and defaults to an exact match, which eliminates the common errors associated with older lookup functions.
What You'll Need
- A Google account with access to Google Sheets.
- A dataset containing a "search key" (the value you are looking for) and a "result range" (the data you want to retrieve).
- Basic familiarity with selecting cell ranges (e.g., A2:A100).
Step-by-Step
- Identify your Search Key: Determine which cell contains the value you want to look up. For example, if you have a list of employee IDs in column A and you want to find the name of the employee with ID "105", cell A2 might be your search key.
- Define the Lookup Range: This is the column or row where Google Sheets should search for your search key. If your employee IDs are listed in column B of a separate sheet, your lookup range would be
'Sheet2'!B2:B50. - Define the Result Range: This is the column or row that contains the data you actually want to return. If the employee names are in column C of that same separate sheet, your result range would be
'Sheet2'!C2:C50. Note that the result range must be the same size as the lookup range. - Enter the Basic Formula: Click on the cell where you want the result to appear and type:
=XLOOKUP(search_key, lookup_range, result_range). For our example, it would look like=XLOOKUP(A2, 'Sheet2'!B2:B50, 'Sheet2'!C2:C50). - Add a Missing Value Message (Optional): XLOOKUP has a built-in argument for when a match isn't found. Instead of getting an
#N/Aerror, you can specify a custom message. Insert this as the fourth argument:=XLOOKUP(A2, 'Sheet2'!B2:B50, 'Sheet2'!C2:C50, "Not Found"). - Set the Match Mode (Optional): By default, XLOOKUP performs an exact match. However, you can add a fifth argument to change this. Use
0for exact match (default),-1for the next smaller item,1for the next larger item, or2for wildcard matches using asterisks (*) or question marks (?). - Set the Search Mode (Optional): The sixth argument determines the direction of the search. Use
1to search from the first entry to the last, or-1to search from the last entry to the first (bottom-to-top). This is particularly useful for finding the most recent entry in a chronological list. - Press Enter: Once the formula is complete, press Enter. Google Sheets will search the lookup range for the key and display the corresponding value from the result range.
Common Mistakes
One of the most frequent errors is mismatching the size of the lookup range and the result range. If your lookup range is A2:A10 (9 cells) but your result range is B2:B11 (10 cells), the formula will return an error. Both ranges must be identical in height or width.
Another common mistake is forgetting that while XLOOKUP defaults to an exact match, the data types must still match. If your search key is a number (e.g., 105) but the lookup range contains that number stored as text (e.g., "105"), XLOOKUP will not find the match. You can fix this by using the VALUE() or TEXT() functions to align the data types.
Users also frequently confuse XLOOKUP with VLOOKUP by trying to select a whole table as the second argument. Unlike VLOOKUP, which requires a table array and a column index number, XLOOKUP requires two separate, specific ranges: one for the search and one for the result.
Tips
To make your formulas more durable, use absolute references (the dollar sign symbol) for your ranges. If you plan to drag your XLOOKUP formula down a column to look up multiple items, change B2:B50 to $B$2:$B$50. This prevents the range from shifting as you copy the formula.
You can use XLOOKUP to return multiple columns at once. If your result range spans multiple columns (e.g., 'Sheet2'!C2:E50), XLOOKUP will "spill" the results into the adjacent cells to the right, providing all the data associated with that search key in one go.
For those dealing with massive datasets, consider using XLOOKUP in combination with ARRAYFORMULA(). This allows you to apply the lookup to an entire column of search keys with a single formula, rather than dragging the formula down hundreds of rows manually.
Troubleshooting
If your formula returns #N/A, the first step is to check for hidden spaces. A cell that looks like "Apple" but is actually "Apple " (with a trailing space) will not match. Use the TRIM() function on your ranges to remove leading and trailing whitespace.
If the formula returns the wrong value, check your match mode. If you accidentally entered 1 or -1 in the fourth or fifth argument, Google Sheets is looking for an approximate match rather than an exact one. Ensure the match mode is left blank or set to 0.
If you see a #REF! error, it usually means the sheet or range you are referencing has been deleted. Double-check that the sheet name in your formula matches the actual tab name at the bottom of your workbook exactly, including spaces and capitalization.
If the formula returns a #VALUE! error, verify that your lookup and result ranges are of the same dimension. If one is a column and the other is a row, or if they are different lengths, the formula cannot map the search key to a result.
Frequently Asked Questions
Can XLOOKUP look to the left?
Yes. Unlike VLOOKUP, which can only search the leftmost column and look to the right, XLOOKUP allows the result range to be anywhere. The result range can be to the left, right, above, or below the lookup range.
Is XLOOKUP better than VLOOKUP?
Generally, yes. It is more flexible, defaults to exact matches, handles missing values internally without needing IFERROR, and doesn't break when you insert or delete columns in your dataset.
Does XLOOKUP work in older versions of Excel?
XLOOKUP is available in Google Sheets and newer versions of Excel (Microsoft 365). If you share a sheet with someone using a very old version of Excel, they may see an error where the formula was used.
How do I do a case-sensitive lookup with XLOOKUP?
XLOOKUP is not case-sensitive by default. To perform a case-sensitive search, you must wrap the search key and the lookup range in the EXACT() function within a different logic structure, as XLOOKUP does not have a built-in case-sensitivity toggle.
Can I use XLOOKUP for horizontal data?
Yes. XLOOKUP replaces both VLOOKUP (vertical) and HLOOKUP (horizontal). If your data is arranged in rows instead of columns, simply select your lookup and result ranges as rows (e.g., A1:Z1 and A2:Z2).