ExcelReady
CourseFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before the interview. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Function guides
  • Blog

Product

  • Certificate

Company

  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Lookups
  3. Find the Last Match in Excel With XLOOKUP

Find the Last Match in Excel With XLOOKUP

By ExcelReady Team·Updated October 30, 2026·7 min read

The short answer

To find the last match, set XLOOKUP's sixth argument, search_mode, to -1 so it searches from the bottom up: =XLOOKUP(F2,A2:A8,C2:C8,"Not found",0,-1). It returns the value from the last row where column A equals F2, such as the most recent price in a list sorted oldest first. XLOOKUP needs Excel 2021 or Microsoft 365.

Key takeaways

  • XLOOKUP's 6th argument, search_mode, sets the direction: 1 is top to bottom (default), -1 is bottom to top.
  • =XLOOKUP(F2,A2:A8,C2:C8,"Not found",0,-1) returns the last match.
  • Don't put -1 in the 5th argument: that is match_mode, where -1 means "exact or next smaller".
  • If the list isn't in date order, find the latest date with MAXIFS and look up both criteria.
  • In older Excel, =LOOKUP(2,1/(A2:A8=F2),C2:C8) returns the last match.
On this page+
  1. Why lookups return the first match
  2. How to find the last match with XLOOKUP
  3. The mistake to avoid: match_mode vs search_mode
  4. How to find the position of the last match
  5. How to find the latest entry when the list isn't sorted
  6. How to get the last non-empty value in a column
  7. How to find the last match in older Excel
  8. Common mistakes when finding the last match
  9. Practise it

XLOOKUP finds the first match by default, but setting its last argument, search_mode, to -1 makes it search from the bottom up and return the last match instead. That's how you get the latest price, the most recent status or the last test score for a person from a log that grows downwards. This guide covers the formula, the argument most people mix up, and options for unsorted data and older Excel.

Why lookups return the first match#

VLOOKUP, MATCH and XLOOKUP all search from the top by default and stop at the first match. That's a problem for logs, where the newest row is at the bottom. Here is a supplier cost list, added to each week:

ABC
1ProductWeekUnit cost
2Paper14.20
3Toner138.00
4Paper24.35
5Pens36.10
6Toner436.50
7Paper54.50
8Pens65.90

With Paper in F2, =XLOOKUP(F2,A2:A8,C2:C8) returns 4.20, the week 1 cost. You want 4.50, the latest one, from week 5. A plain VLOOKUP has the same problem and no way to change direction.

How to find the last match with XLOOKUP#

Add the 4th, 5th and 6th arguments, ending with -1:

Excel formula
=XLOOKUP(F2,A2:A8,C2:C8,"Not found",0,-1)

The result is 4.5. Here is what each argument does:

ArgumentValueMeaning
lookup_valueF2Find "Paper"
lookup_arrayA2:A8in the Product column
return_arrayC2:C8and return the Unit cost
if_not_found"Not found"Text to show if there's no match
match_mode0Exact match (the default)
search_mode-1Search from the last row to the first

XLOOKUP starts at row 8, moves up, and stops at the first "Paper" it meets: row 7. You can leave the 4th and 5th arguments empty with commas, =XLOOKUP(F2,A2:A8,C2:C8,,,-1), but writing them out makes the formula easier to check. XLOOKUP needs Excel 2021, Microsoft 365 or Excel for the web; the XLOOKUP guide and the XLOOKUP function reference cover the basics.

The mistake to avoid: match_mode vs search_mode#

The most common error is putting -1 in the 5th argument instead of the 6th.

Excel formula
=XLOOKUP(F2,A2:A8,C2:C8,,-1)

That -1 is match_mode, which means "exact match, or the next smaller value". For text that exists, it still returns the first match, 4.20, so the formula looks fine but answers the wrong question. Count the commas: search_mode is the sixth argument.

Argument1-12
5th: match_modeExact or next largerExact or next smallerWildcard
6th: search_modeFirst to last (default)Last to firstBinary search (sorted data)

Match modes 2 and wildcards are covered in XLOOKUP wildcard match. You can combine them with search_mode: =XLOOKUP("P*",A2:A8,A2:A8,,2,-1) returns the last product starting with P, which is Pens.

How to find the position of the last match#

To get the row number instead of the value, use XMATCH with the same -1:

Excel formula
=XMATCH(F2,A2:A8,0,-1)

The result is 6: the last Paper is the 6th row of A2:A8. Use it with INDEX to return from any column: =INDEX(C2:C8,XMATCH(F2,A2:A8,0,-1)) also returns 4.5. MATCH has no search direction, so it can only give you the first position; see the MATCH function for what it can do.

How to find the latest entry when the list isn't sorted#

search_mode -1 returns the last row, which is the latest only if the list is in date order. If rows can arrive out of order, find the latest date first, then look up the row with both the product and that date.

Step 1: Find the latest week for the product#

Excel formula
=MAXIFS(B2:B8,A2:A8,F2)

This returns 5, the highest week number for Paper. MAXIFS needs Excel 2019 or later.

Step 2: Look up the row with both criteria#

Excel formula
=XLOOKUP(1,(A2:A8=F2)*(B2:B8=MAXIFS(B2:B8,A2:A8,F2)),C2:C8)

This returns 4.5, wherever the week 5 row sits in the list. Multiplying the two tests is the standard way to look up on two conditions; see lookup with multiple criteria for how it works.

How to get the last non-empty value in a column#

The same idea finds the last filled cell, such as the latest reading in a column that grows each day:

Excel formula
=XLOOKUP(TRUE,C2:C100<>"",C2:C100,,0,-1)

C2:C100<>"" is TRUE for every filled cell. Searching from the bottom, XLOOKUP returns the value of the last one: here, 5.9. The range can extend past your data, so new rows are picked up automatically.

How to find the last match in older Excel#

Without XLOOKUP, the classic formula uses LOOKUP:

Excel formula
=LOOKUP(2,1/(A2:A8=F2),C2:C8)

1/(A2:A8=F2) gives 1 for matching rows and #DIV/0! for the rest. LOOKUP searches for 2, can't find it, ignores the errors, and settles on the last 1 in the list. It returns the matching value from C2:C8: 4.5. It works in all versions without Ctrl+Shift+Enter, but it's hard to read, so add a note next to it.

Two other choices: sort the data newest first (Data > Sort, Largest to Smallest on the date column) so a normal VLOOKUP finds the latest row, or use a pivot table with the MAX of the date.

Common mistakes when finding the last match#

  • -1 in the wrong slot. As above, the 5th argument is match_mode; search_mode is the 6th.
  • Assuming "last" means "latest". search_mode -1 returns the bottom-most row. If the data isn't in date order, use the MAXIFS method.
  • Ranges of different sizes, such as A2:A8 and C2:C9, which return #VALUE!.
  • Extra spaces or text-numbers in the lookup column, which make XLOOKUP skip the row you expect. Clean the data with TRIM, or convert text to numbers.
  • Forgetting if_not_found. Without it, a product with no rows shows #N/A, which can break totals that use the result.

Practise it#

Try the live exercise on this page to return the latest Paper cost. Then practise XLOOKUP wildcards and match modes in a live spreadsheet, where you'll use XLOOKUP's optional arguments, including the match modes this guide warns you not to confuse with search_mode.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

The cost list is in date order, oldest first. In G2, return the latest unit cost for the product in F2. Use XLOOKUP with "Not found", match_mode 0 and search_mode -1.

fx
ABCDEFGH
1
Product
Week
Unit cost
Product
Latest cost
2
Paper
1
4.2
Paper
3
Toner
1
38
4
Paper
2
4.35
5
Pens
3
6.1
6
Toner
4
36.5
7
Paper
5
4.5
8
Pens
6
5.9
9
10
11

Tip: Write a normal XLOOKUP, then add "Not found", 0 for exact match, and -1 to search from the bottom.

Practise this in a lesson

LessonXLOOKUP wildcards and match modesSearch partial names with XLOOKUP's wildcard mode, and place values into tiers with next-smaller and next-larger matches.Function guideXLOOKUPXLOOKUP explained with real examples: exact matches, looking left and custom not-found messages, plus a live exercise to try now.

Frequently asked questions

How do I get XLOOKUP to return the last match?

+

Set the sixth argument, search_mode, to -1: =XLOOKUP(F2,A2:A8,C2:C8,"Not found",0,-1). XLOOKUP then searches from the last row up and returns the first match it meets, which is the last one in the list.

Can VLOOKUP find the last match?

+

No. VLOOKUP always searches from the top. Use XLOOKUP with search_mode -1, sort the data newest first, or use the LOOKUP(2,1/...) formula in older versions.

What is the difference between match_mode and search_mode in XLOOKUP?

+

match_mode (5th argument) controls how values match: exact, next smaller, next larger or wildcard. search_mode (6th argument) controls the direction: first to last or last to first.

How do I find the latest entry by date, not by position?

+

Find the latest date with MAXIFS, then look up the row that has both the item and that date: =XLOOKUP(1,(A2:A8=F2)*(B2:B8=MAXIFS(B2:B8,A2:A8,F2)),C2:C8).

How do I get the last non-empty value in a column?

+

Use =XLOOKUP(TRUE,C2:C100<>"",C2:C100,,0,-1). It looks for the last cell that is not empty and returns its value.

Sources

  • XLOOKUP function - Microsoft Support
  • XMATCH function - Microsoft Support
  • MAXIFS function - Microsoft Support

Written and checked by the ExcelReady Team. First published October 30, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. Why lookups return the first match
  2. How to find the last match with XLOOKUP
  3. The mistake to avoid: match_mode vs search_mode
  4. How to find the position of the last match
  5. How to find the latest entry when the list isn't sorted
  6. How to get the last non-empty value in a column
  7. How to find the last match in older Excel
  8. Common mistakes when finding the last match
  9. Practise it

Keep reading

Lookups· 6 min read

The MATCH Function in Excel

MATCH finds a value in a row or column and returns its position, not the value itself. =MATCH("Marco",B2:B7,0) returns 4 if Marco is the 4th name in B2:B7. Always use 0 as the third argument for an exact match. MATCH is most useful inside INDEX, as =INDEX(A2:A7,MATCH(F2,B2:B7,0)), to look up in any direction.

Lookups· 6 min read

Lookup With Multiple Criteria in Excel

To look up a value that must match two or more criteria, multiply the tests and look up 1: =XLOOKUP(1,(A2:A8=F2)*(B2:B8=F3),C2:C8). Each test gives 1 for TRUE and 0 for FALSE, so only rows that pass every test become 1. In Excel 2019 and earlier, use =INDEX(C2:C8,MATCH(1,(A2:A8=F2)*(B2:B8=F3),0)) or a helper column.

Lookups· 7 min read

XLOOKUP in Excel: Everything a Beginner Needs

XLOOKUP finds a value in one range and returns the matching item from another: =XLOOKUP(G2,B2:B9,A2:A9). It defaults to an exact match, can return a column on either side, and has a built-in if_not_found message instead of #N/A. It needs Excel 2021, Excel 2024 or Microsoft 365; it isn't in Excel 2019 or earlier.

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback. The first lessons are free, with no download.

Start learning for free