Skip to content
AnIntent

How to Use XLOOKUP in Google Sheets: Look Left, Fix #N/A, Find the Last Match

Write XLOOKUP formulas in Google Sheets that look left, replace #N/A with your own text, and find the last match.

AnIntent Editorial · · 3 min read

Hands typing on a laptop displaying a data spreadsheet
Photo by Gorilla ROI Data Connector on Unsplash
In this article
  1. The XLOOKUP syntax that applies to Sheets
  2. Write a basic XLOOKUP
  3. Look up a column to the left
  4. Replace #N/A with your own text
  5. Find the last match instead of the first
  6. Approximate and wildcard matches
  7. When XLOOKUP returns an error
Share this article

XLOOKUP in Google Sheets finds a value in one column or row and returns the matching entry from another. This guide covers the basic formula, looking up a column to the left, showing your own text instead of #N/A, and finding the last match instead of the first.

The XLOOKUP syntax that applies to Sheets

Google's XLOOKUP help page gives the Sheets syntax as:

XLOOKUP(search_key, lookup_range, result_range, missing_value, match_mode, search_mode)

The page describes each argument this way:

  • search_key: the value to find, such as 42, "Cats" or a cell like B24.
  • lookup_range: where to search. It must be a single row or a single column.
  • result_range: what to return. Its row or column size should match lookup_range.
  • missing_value (optional): what to return when nothing matches. The default is #N/A.
  • match_mode (optional, default 0): 0 is an exact match and 2 is a wildcard match. 1 and -1 are approximate options, covered below.
  • search_mode (optional, default 1): 1 searches first to last, -1 searches last to first, 2 is a binary search on a range sorted ascending, -2 is a binary search on a range sorted descending.

Write a basic XLOOKUP

  1. Click the cell where you want the result.
  2. Type =XLOOKUP( followed by the value to find, the column to search, and the column to return.
  3. Press Enter.

This formula looks up "Apple" in column A and returns the value from column E:

=XLOOKUP("Apple", A2:A, E2:E)

Swap "Apple" for a cell reference if you want the lookup to change with your input. A drop-down list in that cell makes a tidy picker.

Look up a column to the left

XLOOKUP has no such rule because the lookup and result ranges are separate arguments. This formula searches column E and returns column A:

=XLOOKUP("Apple", E2:E7, A2:A7)

Replace #N/A with your own text

Put your message in the fourth argument, missing_value:

=XLOOKUP("Apple", A2:A, E2:E, "Not found")

If "Apple" isn't in column A, the cell shows "Not found" instead of #N/A. Coupler's guide uses the same pattern with a message like "No office there". You can also use an empty string "" to leave the cell blank.

Find the last match instead of the first

By default XLOOKUP searches top to bottom and stops at the first hit. Set search_mode to -1 to search from the bottom up, which gives you the last occurrence.

=XLOOKUP("Apple", A2:A, E2:E, "Not found", 0, -1)

If you're not sure whether your list has repeats, highlight duplicates with COUNTIF first.

Approximate and wildcard matches

For an approximate match, set match_mode to 1 or -1. Guides describe the direction of these two options differently, so test which way each one rounds on your own data before relying on it:

=XLOOKUP(B2, A2:A, E2:E, "No band", -1)

For a wildcard match, set match_mode to 2. Google's page does not list which wildcard characters it accepts, so check the behaviour in your own sheet before relying on it.

The binary search options (search_mode 2 and -2) only belong on ranges sorted ascending or descending respectively. Don't use them on unsorted data.

When XLOOKUP returns an error

The most common cause is mismatched ranges. lookup_range must be a single row or column, and result_range should be the same size. A formula like XLOOKUP("Apple", A2:A7, E2:E) mixes a fixed range with an open-ended one. Make both ranges start and end on the same rows, or make both open-ended.

If you get #N/A on a value you can see, the default exact match is doing its job: the cell contents differ somehow from the search key. Add a missing_value so the result is readable while you check the data.

Common questions

What is the difference between XLOOKUP and VLOOKUP in Google Sheets?

VLOOKUP takes a table and a column number and can only return columns to the right. XLOOKUP takes a separate lookup range and result range, so it can return a column to the left, and it has built-in options for a missing value, match mode and search direction.

How do I get the last match with XLOOKUP?

Set search_mode to -1, which searches from the last entry to the first. You must fill in missing_value and match_mode before it, for example =XLOOKUP("Apple", A2:A, E2:E, "Not found", 0, -1).

Which wildcard characters does XLOOKUP support in Sheets?

Google's help page says match_mode 2 is a wildcard match but doesn't list the characters, so check how it behaves in your own sheet.

Person working on a laptop with a spreadsheet outdoors
How-to

How to Highlight Duplicates in Google Sheets With a COUNTIF Formula

Use conditional formatting and a COUNTIF custom formula to colour every repeated value in a Google Sheets column without deleting anything.

· 4 min

More in Cloud & Productivity Software