CodeMIRAI
0 XP

XLOOKUP

2 min read Quiz included

XLOOKUP (Microsoft 365, Excel 2021 and later, and Google Sheets) does everything VLOOKUP does, more simply and with fewer traps.

Excel formula
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

This lesson uses an employee list in A1:D6:

ABCD
1IDNameDepartmentSalary
2E101GraceEngineering210000
3E102AlanEngineering165000
4E103MayaSales150000
5E104OmarSales92000
6E105HanaSupport71000

The basics

Excel formula
=XLOOKUP("E104", A2:A6, B2:B6)        → Omar
=XLOOKUP("E104", A2:A6, D2:D6)        → 92000
ProductsA: IDB: NameC: PriceP1Pen10P2Pad45P3Ink120=XLOOKUP("P2", A:A, C:C)1 find "P2" in column A2 stay on that row3 return column C: 45
XLOOKUP searches one range and returns the item at the same position from another, so the result column can be anywhere.

Give it what to find, where to find it, and which column to return. Unlike VLOOKUP:

  • it does an exact match by default, so there's no FALSE to forget;
  • the return column is a range, not a column number, so inserting a column doesn't break it.

Looking left

Excel formula
=XLOOKUP("Maya", B2:B6, A2:A6)        → E103

The return range can be to the left of the lookup range, which VLOOKUP simply can't do.

When nothing matches

Excel formula
=XLOOKUP("E999", A2:A6, B2:B6)                        → #N/A
=XLOOKUP("E999", A2:A6, B2:B6, "No such employee")    → No such employee

The fourth argument replaces the #N/A error with a message of your choice, with no need to wrap the formula in IFERROR.

Returning several columns

Excel formula
=XLOOKUP("E102", A2:A6, B2:D6)        → Alan | Engineering | 165000

With a multi-column return range, the results spill into the cells to the right: one formula fills the name, department and salary.

Approximate matches: bands and grades

A grade table with each band's lower limit in F2:F6:

FG
1FromGrade
20F
350D
460C
575B
690A
Excel formula
=XLOOKUP(82, F2:F6, G2:G6, , -1)      → B     the band starting at 75
=XLOOKUP(90, F2:F6, G2:G6, , -1)      → A     an exact match counts too

The fifth argument, match_mode, chooses the kind of match:

match_modeFinds
0 (the default)an exact match only
-1an exact match, or else the next smaller value
1an exact match, or else the next larger value
2a wildcard match, using * and ?

With -1, 82 has no exact match, so XLOOKUP takes the next smaller limit, 75. Unlike VLOOKUP's approximate mode, the table doesn't even need to be sorted.

Wildcards

Excel formula
=XLOOKUP("Ma*", B2:B6, D2:D6, , 2)    → 150000    the first name starting with Ma

Searching from the bottom

Excel formula
=XLOOKUP("Sales", C2:C6, B2:B6)             → Maya    the first Sales row
=XLOOKUP("Sales", C2:C6, B2:B6, , 0, -1)    → Omar    the last Sales row

The sixth argument, search_mode, set to -1, searches from the last row upwards: useful for finding the most recent entry in a log or a list of transactions.

Finished this lesson?Mark it complete to earn +20 XP and move your progress on.