FormulaCraft

How to look up the last matching value in Excel and Google Sheets

Topic:Lookups (any direction)
Excel & Google Sheets
=LOOKUP(2,1/(A2:A6=D2),B2:B6)

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Place your lookup value in a cell (e.g. D2).
  2. 2In the result cell, enter =LOOKUP(2,1/(A2:A6=D2),B2:B6).
  3. 3The expression A2:A6=D2 creates an array of TRUE/FALSE; 1/(…) converts TRUE to 1 and FALSE to #DIV/0!.
  4. 4LOOKUP ignores errors and scans to the last 1, effectively finding the last match.

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

Why does LOOKUP(2,...) work when there is no 2 in the array?

LOOKUP finds the largest value less than or equal to the lookup value. Since the array only contains 1s (and errors), LOOKUP returns the position of the last 1, which is the last match.

Does this work if the lookup column is unsorted?

Yes — the 1/(range=value) trick works on unsorted data because LOOKUP is searching a computed array, not the raw data.

More on Lookups (any direction)

See all →

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: