FormulaCraft

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

Topic:Lookups (any direction)
Excel & Google Sheets
=IFERROR(INDEX($B$2:$B$6,SMALL(IF($A$2:$A$6="Alice",ROW($A$2:$A$6)-ROW($A$2)+1),2)),"")

Verified example

Computed by a real spreadsheet engine on the sample data below.

NameTask
AliceDesign
BobDev
AliceReview
AliceTesting

=IFERROR(INDEX($B$2:$B$6,SMALL(IF($A$2:$A$6="Alice",ROW($A$2:$A$6)-ROW($A$2)+1),2)),"")

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. 1Build the IF array that returns the relative row numbers of matches: IF($A$2:$A$100="Alice",ROW($A$2:$A$100)-ROW($A$2)+1) produces row numbers where Alice appears, FALSE elsewhere.
  2. 2Use SMALL(...,n) to extract the nth smallest row number from that array — SMALL(...,2) gives the 2nd match's row.
  3. 3Wrap in INDEX to retrieve the value: =INDEX($B$2:$B$100,SMALL(IF(...),2)). In Excel 2019 confirm with Ctrl+Shift+Enter; wrap in IFERROR to suppress errors when fewer than n matches exist.

Tips

Working on a sheet you inherited? Run the Auditor on the whole file first — it flags every #REF!, #N/A, broken column pattern, and inconsistent formula in seconds, free, no signup.

Frequently asked

How do I look up the last matching value instead of the nth?

Use LARGE instead of SMALL with 1 as the k argument: =INDEX($B$2:$B$100,LARGE(IF($A$2:$A$100="Alice",ROW($A$2:$A$100)-ROW($A$2)+1),1)) returns the last match.

More on Lookups (any direction)

See all →

Formulas used

Related tasks

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

Last reviewed: