How-to recipes · Lookups

How to return multiple matches in Excel

VLOOKUP returns only the first match. List every matching row with FILTER, join matches in one cell with TEXTJOIN, or use INDEX and AGGREGATE in older Excel.

Intermediate FILTER TEXTJOIN INDEX AGGREGATE ROW ROWS IFERROR

A lookup function answers what is the first value that matches? That is fine for a price list where every code is unique, but often you need all matching rows: every order placed by one customer, every course a student takes, every ticket assigned to one agent. VLOOKUP, XLOOKUP and INDEX/MATCH all stop at the first hit. This recipe shows how to return every match, either as a list or joined into a single cell.

The example data

Six orders in A1:C7. Alpha Ltd placed three of them: SO-501, SO-503 and SO-505.

Microsoft 365 and Excel 2021: FILTER

FILTER was made for this. Give it the columns you want back and a condition, and it spills every matching row:

E2fx=FILTER(B2:C7,A2:A7="Alpha Ltd","No orders")
ABCDEF
1CustomerOrderAmount
2Alpha LtdSO-5011200SO-5011200
3BrightwaySO-502450SO-503800
4Alpha LtdSO-503800SO-505950
5Cedar CoSO-504300
6Alpha LtdSO-505950
7BrightwaySO-506620

Three rows match, so the result spills over E2:F4. In a real sheet, replace "Alpha Ltd" with a cell reference.

  • B2:C7: the columns to return. Use A2:C7 to include the customer column too.
  • A2:A7="Alpha Ltd": the condition, evaluated for every row.
  • "No orders": what to show when nothing matches; otherwise FILTER returns #CALC!.

Combine conditions by multiplying them (AND) or adding them (OR): =FILTER(B2:C7,(A2:A7="Alpha Ltd")*(C2:C7>=900)) returns only SO-501 and SO-505. Sort the result with =SORT(FILTER(...),2,-1) to put the largest amount first. Leave enough empty cells below and to the right, or you will see #SPILL!.

All matches in one cell

For a compact report, join the matches with TEXTJOIN:

Formula
=TEXTJOIN(", ",TRUE,FILTER(B2:B7,A2:A7="Alpha Ltd"))

The result is a single text: SO-501, SO-503, SO-505. The TRUE tells TEXTJOIN to skip empty values.

Excel 2019: TEXTJOIN with IF

Excel 2019 has TEXTJOIN but not FILTER. Use IF to blank out the rows that do not match: =TEXTJOIN(", ",TRUE,IF(A2:A7="Alpha Ltd",B2:B7,"")), confirmed with Ctrl+Shift+Enter. Excel 2016 has neither function, so use the next method.

Excel 2016 and 2019: INDEX + AGGREGATE, copied down

The classic approach returns the 1st match in the first cell, the 2nd in the next, and so on. AGGREGATE finds the row number of the k-th match, and INDEX returns the value at that row. In this grid the customer to find is in F1 and the formula sits in F2:

F2fx=IFERROR(INDEX($B$2:$B$7,AGGREGATE(15,6,(ROW($A$2:$A$7)-ROW($A$2)+1)/($A$2:$A$7=$F$1),ROWS($F$2:F2))),"")
ABCDEF
1CustomerOrderAmountFindAlpha Ltd
2Alpha LtdSO-5011200Order 1SO-501
3BrightwaySO-502450
4Alpha LtdSO-503800
5Cedar CoSO-504300
6Alpha LtdSO-505950
7BrightwaySO-506620

Copy F2 down to F3, F4 and so on. F3 returns SO-503, F4 returns SO-505, and F5 onwards stay blank.

Result: SO-501

  1. ROW($A$2:$A$7)-ROW($A$2)+1 produces the positions {1;2;3;4;5;6}.
  2. Dividing by ($A$2:$A$7=$F$1) keeps the positions of matching rows (divided by 1) and turns the others into #DIV/0! (divided by 0): {1;#DIV/0!;3;#DIV/0!;5;#DIV/0!}.
  3. AGGREGATE(15,6,...,k) is SMALL (function 15) with option 6, ignore errors, so it returns the k-th smallest valid position. No Ctrl+Shift+Enter needed.
  4. ROWS($F$2:F2) is 1 in the first cell and grows to 2, 3, ... as you copy down, so each cell asks for the next match.
  5. INDEX returns the order number at that position, and IFERROR shows a blank once the matches run out.

Copy the same formula to the next column and change $B$2:$B$7 to $C$2:$C$7 to bring back the amounts as well.

Pitfalls

  • The ranges in the INDEX/AGGREGATE formula must all start in the same row, and ROW($A$2) must point to the first data row, otherwise every result is shifted.
  • Copy the old-style formula down far enough for the largest possible number of matches; it does not grow by itself like FILTER does.
  • FILTER results cannot be edited cell by cell and cannot be placed inside an Excel table. Put them next to the table instead.
  • TEXTJOIN fails with #VALUE! if the joined text exceeds 32,767 characters.
Tip. If you need only one specific match, such as the second or the last, see How to get the nth match in Excel and How to find the last value in a column in Excel. Background on spilling formulas is in Dynamic arrays: spill, FILTER, SORT, UNIQUE, SEQUENCE and #, and on lookups in Lookup guide: VLOOKUP vs INDEX/MATCH vs XLOOKUP.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 15 KB

More how-to recipes