How to Use XLOOKUP in Excel (With Real Examples)

XLOOKUP finds a value in one column (or row) and returns the matching item from another. The basic formula needs just three pieces: =XLOOKUP(what_to_find, where_to_look, what_to_return). For example, =XLOOKUP(F2,A2:A9,C2:C9) finds the employee ID in F2 within A2:A9 and returns that person’s department from C2:C9. It matches exactly by default, can look left or right, and lets you choose your own “not found” message.

XLOOKUP is available in Excel for Microsoft 365 (Windows and Mac), Excel 2024, Excel 2021, Excel for the web, and the Excel apps for iPhone, iPad, and Android. It is not available in Excel 2019, Excel 2016, or older. If you use one of those, see the section on older versions near the end.

Jump to a section

The six parts of XLOOKUP

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

Only the first three are required. The other three are optional and can be skipped by simply closing the parenthesis.

Argument Required? What it does
lookup_value Yes The value you want to find, usually a cell such as F2.
lookup_array Yes The single column or row to search, such as A2:A9.
return_array Yes The column (or columns) holding the answer, such as C2:C9. It should cover the same rows as the lookup array.
if_not_found No What to show when there is no match, such as "Not found". Without it, you get #N/A.
match_mode No 0 exact match (default); -1 exact or next smaller; 1 exact or next larger; 2 wildcard match.
search_mode No 1 search first to last (default); -1 search last to first; 2 and -2 fast binary search on data sorted ascending or descending.

The big difference from VLOOKUP is that you point at the lookup column and the answer column separately. There’s no column number to count, and inserting a new column between them won’t break the formula.

Advertisements

Write your first XLOOKUP

This sample staff list sits in A1:D9. You’ll type an ID into F2 and have G2 show the department.

A: Staff ID B: Name C: Department D: Extension
2 1001 Ana Ruiz Sales 214
3 1002 Ben Cole Finance 305
4 1003 Chloe Park Marketing 118
5 1004 Dev Patel IT 402
6 1005 Erin Shaw Sales 220
7 1006 Frank Ito HR 131
8 1007 Gina Lowe Finance 309
9 1008 Hal Moss IT 415
  1. Type a test ID. Click F2 and type 1004. Put the label “Department” in G1 if you like.
  2. Select the result cell. Click G2.
  3. Start the formula. Type =XLOOKUP(. A tooltip appears listing the six arguments, with the current one in bold. Optional arguments are shown in square brackets.
  4. Point to the value to find. Click F2 and type a comma.
  5. Select the column to search. Drag down A2:A9 (the Staff IDs) and type a comma.
  6. Select the column to return. Drag down C2:C9 (Department). Make sure it starts and ends on the same rows as the lookup column.
  7. Finish. Type ) and press Enter. The formula is =XLOOKUP(F2,A2:A9,C2:C9) and G2 shows IT.
  8. Test it. Change F2 to 1007 and G2 changes to Finance.

If you’ll copy the formula to other rows, lock the two ranges first: click each range in the formula bar and press F4 so they read $A$2:$A$9 and $C$2:$C$9. Leave F2 unlocked so it shifts to F3, F4, and so on.

Prefer forms to typing? Go to Formulas > Lookup & Reference and choose XLOOKUP. Excel for Windows opens the Function Arguments box with a field for each argument and a live preview of the result. On a Mac the same choice opens the Formula Builder pane.

Replace #N/A with your own message

Type an ID that doesn’t exist, such as 1010, and the formula returns #N/A. Add a fourth argument to show something clearer:

=XLOOKUP(F2,A2:A9,C2:C9,"No such ID")

The message can also be a number (0), an empty result (""), or even another XLOOKUP that searches a second list. For instance, =XLOOKUP(F2,A2:A9,C2:C9,XLOOKUP(F2,Contractors!A2:A20,Contractors!C2:C20,"Not found")) checks the staff list first, then a Contractors sheet. Because this message is built in, you rarely need to wrap XLOOKUP in IFERROR or IFNA.

Look to the left

VLOOKUP can only return columns to the right of the one it searches. XLOOKUP doesn’t care about order. To find the Staff ID for a name typed in F5:

=XLOOKUP(F5,B2:B9,A2:A9)

With “Gina Lowe” in F5, the result is 1007, even though the ID column sits to the left of the name column. You never need to rearrange columns or switch to INDEX and MATCH for this.

Return several columns at once

Make the return array wider than one column and XLOOKUP hands back the whole matching row slice:

=XLOOKUP(F2,A2:A9,B2:D9)

Enter this in G2 with 1004 in F2, and Excel fills G2:I2 with Dev Patel, IT, and 402. This automatic overflow into neighboring cells is called spilling. Only G2 holds the formula; the other cells show a thin blue border when selected and can’t be edited on their own.

Spilling needs empty space. If anything is already in H2 or I2, the formula shows #SPILL! until you clear those cells. Spilled formulas also can’t live inside a formatted Excel table, so put this one in ordinary cells next to the table.

You can also give it a list of values to look up. =XLOOKUP(F2:F5,A2:A9,C2:C9) returns four departments at once, one for each ID in F2:F5.

Find the closest match for tiers and brackets

Use match_mode when your value won’t appear exactly, such as a sales amount that falls between commission tiers.

K: Sales from L: Commission
2 0 2%
3 10,000 4%
4 25,000 6%
5 50,000 8%

With 31,500 in N2:

=XLOOKUP(N2,K2:K5,L2:L5,"",-1)

The -1 says “use an exact match if there is one, otherwise the next smaller value.” The next smaller value is 25,000, so the result is 6%. The "" leaves the not-found message blank. Change the -1 to 1 to get the next larger value instead, which suits lists of upper limits, such as package size caps or shipping weight bands.

Unlike VLOOKUP’s approximate match, these modes don’t need the list sorted. Only the binary search options (search_mode 2 and -2) require sorted data, and they can return wrong answers if the data isn’t sorted, so leave them alone unless you’re working with very large lists.

Match part of a word

Wildcards work only when you set match_mode to 2. An asterisk * stands for any run of characters and a question mark ? stands for one character.

=XLOOKUP("Chlo*",B2:B9,C2:C9,"No match",2)

That returns Marketing for Chloe Park. To search for a word typed in F8 anywhere in the name, use "*"&F8&"*" as the first argument. To look for a literal asterisk or question mark, put a tilde before it (~*). If you forget the 2, Excel treats the asterisk as an ordinary character and returns #N/A or your not-found message.

Find the last match instead of the first

By default XLOOKUP searches top to bottom and stops at the first hit. Setting search_mode to -1 searches bottom to top, which is handy for a log where the newest entry is at the bottom. With “Sales” in F10:

=XLOOKUP(F10,C2:C9,B2:B9,,,-1)

This returns Erin Shaw, the last Sales person in the list, instead of Ana Ruiz. The empty commas skip the optional arguments you don’t need; Excel uses their defaults.

Row and column lookups together

XLOOKUP also searches across a row, so it replaces HLOOKUP. Select a row for the lookup array and a matching row for the return array, such as =XLOOKUP("Mar",B1:M1,B5:M5) to fetch March from row 5 of a month-by-month report.

To find where a row label and a column header cross, nest one XLOOKUP inside another. Suppose a report has regions in A2:A6, months in B1:M1, and figures in B2:M6. With a region in P1 and a month in P2:

=XLOOKUP(P1,A2:A6,XLOOKUP(P2,B1:M1,B2:M6))

The inner formula returns the whole column for the chosen month, and the outer formula picks the row for the chosen region from that column.

Because XLOOKUP returns a reference, you can also total everything between two matches. =SUM(XLOOKUP("Feb",B1:M1,B5:M5):XLOOKUP("Apr",B1:M1,B5:M5)) adds February, March, and April. For simpler totals, the usual approaches for summing a column in Excel work on XLOOKUP results too.

Matching on two conditions

When one column isn’t enough to identify a row, join the conditions with multiplication. To find the extension for someone named “Ben Cole” in Finance, with the name in F12 and the department in G12:

=XLOOKUP(1,(B2:B9=F12)*(C2:C9=G12),D2:D9,"No match")

Each comparison creates a list of TRUE and FALSE values. Multiplying them gives 1 only where both are true, and XLOOKUP looks for that 1. The result is 305.

When XLOOKUP gives an error

What you see Why it happens What to do
#NAME? Your version of Excel doesn’t include XLOOKUP (Excel 2019, 2016, or older), or the function name is misspelled. Check the spelling. If it’s spelled correctly, use INDEX and MATCH (below), or open the file in Excel for the web or Microsoft 365.
#N/A when the value looks like it’s there Extra spaces in the data, or a number stored as text on one side and a real number on the other. Clean spaces with =TRIM() or Find and Replace. Convert text-numbers with the green warning icon’s Convert to Number, or Data > Text to Columns > Finish.
#N/A when the value really is missing Expected when there’s no match and no fourth argument. Add an if_not_found message.
#VALUE! The lookup array and return array are different heights (for example A2:A9 and C2:C20), or the lookup array covers more than one column. Make both ranges start and end on the same rows, and search only one column or row.
#SPILL! A multi-value result has no room, or the formula is inside an Excel table. Select the cell, click the warning icon, choose Select Obstructing Cells, and clear them. Move spilling formulas outside tables.
#REF! after closing another file The formula points to a different workbook that isn’t open. Open the source workbook, then recalculate.
Wrong result from a tier lookup match_mode -1 and 1 are swapped, or a binary search mode is used on unsorted data. Use -1 for “start of band” lists and 1 for “upper limit” lists. Set search_mode back to 1.
Wildcard search returns not found match_mode isn’t set to 2. Add 2 as the fifth argument.

For the full list of argument values, see Microsoft’s XLOOKUP function reference, and for blocked results, its page on fixing #SPILL! errors. If stray spaces are the problem across a whole column, Excel’s Find and Replace can strip them in one pass.

Confirming the formula is right

Test with a value you can check by eye, then with one you know is missing to confirm the not-found message appears. Click the result and use Formulas > Evaluate Formula to step through how Excel reads it. If you need fixed results that won’t change, copy them and use Paste Special > Values; Ctrl+Z undoes the paste if you get it wrong.

If you have Excel 2019 or earlier

A workbook with XLOOKUP will still open in Excel 2019 or 2016, but those cells won’t calculate properly there. If you share files with people on older versions, use INDEX and MATCH, which does the same job:

=INDEX(C2:C9,MATCH(F2,A2:A9,0))

MATCH finds the position of the ID in A2:A9 (the 0 means exact), and INDEX returns the item at that position from C2:C9. Like XLOOKUP, it can look left. To show a message instead of #N/A, wrap it: =IFNA(INDEX(C2:C9,MATCH(F2,A2:A9,0)),"No such ID"). VLOOKUP is the other option when the answer column is to the right of the lookup column.

XLOOKUP questions people ask

Is XLOOKUP better than VLOOKUP?

For most new work, yes. It defaults to an exact match, looks in either direction, has a built-in not-found message, returns several columns at once, and doesn’t break when columns are inserted. VLOOKUP is still the safer choice when the file has to work in Excel 2019 or earlier.

Is XLOOKUP case-sensitive?

No. “sales” and “Sales” match the same cell. For a case-sensitive lookup, use the EXACT function as the condition: =XLOOKUP(TRUE,EXACT(B2:B9,F2),C2:C9).

Can XLOOKUP search another sheet?

Yes. While typing the formula, click the other sheet’s tab and select the ranges there. Excel adds the sheet name automatically, for example =XLOOKUP(F2,Staff!A2:A9,Staff!C2:C9).

Do I need to sort my data?

No, not for exact matches or for the next smaller and next larger modes. Sorting is required only for the binary search modes, 2 and -2.

Why does XLOOKUP show 0 instead of a blank?

When the matching cell in the return column is empty, XLOOKUP shows 0. Append an empty string to force a blank-looking text result: =XLOOKUP(F2,A2:A9,D2:D9)&"". Note that this turns numbers into text.

Does XLOOKUP work in Excel on iPhone or iPad?

Yes. The Excel apps for iPhone, iPad, and Android support it, and so does Excel for the web, so a free Microsoft account is enough to use it.

Can XLOOKUP return all matches, not just one?

No, it returns one match per lookup value. To list every row that matches, use the FILTER function, which is available in the same versions as XLOOKUP.

Next step

Recreate the staff list, try the basic formula, then add a not-found message and a multi-column return. Once those feel natural, replace one VLOOKUP in a workbook you already use and compare how much shorter the XLOOKUP version is.

Advertisements