XLOOKUP: find an employee’s department

Lesson 19 of 54

XLOOKUP finds a value in one column (or row) and returns the matching value from another. It replaces VLOOKUP and HLOOKUP in Excel 365, Excel 2021 and Google Sheets.

In cell F2, write a formula that finds the Department of the employee ID typed in E2.

F2
ABCDEF
1IDNameDepartmentFind IDDepartment
2E-104Ana RuizFinanceE-221
3E-118Luis PazSales
4E-221Marta GilMarketing
5E-305Jorge LeonIT

Type in the formula bar above and press Enter to check.

Skip

How XLOOKUP works

Syntax

=XLOOKUP(search_key, lookup_range, return_range, [if_not_found], [match_mode], [search_mode])
search_key
The value you are looking for, usually a cell like E2.
lookup_range
The single column (or row) to search in.
return_range
The column (or row) to return a value from. Same size as lookup_range.
if_not_found
Optional. What to show when there is no match, for example "Not found". Without it you get #N/A.
match_mode
Optional. 0 = exact match (the default), -1 = exact or next smaller, 1 = exact or next larger, 2 = wildcards.
search_mode
Optional. 1 = search from the top (default), -1 = search from the bottom, to find the last match.

Example

Product codes are in A2:A50 and prices in D2:D50. You type a code in G2 and want its price.

=XLOOKUP(G2, A2:A50, D2:D50, "Not found")

Returns the price for that code, or "Not found" if the code is not in the list.

Common mistakes

  • lookup_range and return_range have different sizes (A2:A50 vs D2:D40). They must cover the same rows, or you get #VALUE!.
  • Selecting a whole table as lookup_range. XLOOKUP searches one column, so give it just that column.
  • Forgetting $ signs before filling down. Lock the ranges ($A$2:$A$50) so they don't shift.
  • Using an older Excel. XLOOKUP needs Excel 365 or 2021; Excel 2019 and earlier show #NAME?. Use INDEX and MATCH there.

Questions people ask

What is the difference between XLOOKUP and VLOOKUP?

VLOOKUP only looks to the right and needs a column number, which breaks when columns are added. XLOOKUP takes the return column directly, can look left, defaults to an exact match and has a built-in "not found" value.

Does XLOOKUP work in Google Sheets?

Yes. Google Sheets added XLOOKUP in 2022 with the same arguments as Excel.

Can XLOOKUP return more than one column?

Yes. Give a return_range several columns wide, like C2:E50, and the results spill into the cells to the right.

Practice it above: type the formula in the formula bar and press Enter to check.