Cellwise Start free

Excel guide · 6 min read

How to find the row number of a value in Excel

Quick answer=MATCH(G1,B4:B11,0) returns the position of the value inside the range, not the sheet row. Add the offset to get the real row: =MATCH(G1,B4:B11,0)+ROW(B4)-1. In Excel 365 or 2021, =XMATCH(G1,B4:B11,0,-1)+ROW(B4)-1 gives the row of the last match, and =FILTER(ROW(B4:B11),B4:B11=G1) lists every matching row.

Sample data

Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.

ABCDEFG
1Order log, Q3FindHarbor Foods
2
3Order IDCustomerRegionAmount
4SO-2201Harbor FoodsWest1250
5SO-2202Pinecrest CafeEast480
6SO-2203Lumen DentalWest2100
7SO-2204Harbor Foods West760
8SO-2205Pinecrest CafeEast395
9SO-2206Harbor FoodsNorth1840
10SO-2207Oakline StudioEast620
11SO-2208Harbor FoodsWest910

Download this sheet as an Excel practice file (.xlsx)

MATCH gives the position in the range, not the row

The sheet is an order log with a title in row 1 and headers in row 3, so the first order sits in row 4. G1 holds the customer to find. MATCH(lookup_value, range, 0) searches the range and returns where the first match is, counted from the top of that range.

That number is the position, and it is exactly what INDEX wants, which is why INDEX and MATCH work together. It is not the row number you see on the left of the sheet. Harbor Foods is the 1st item in B4:B11 but lives in row 4. The two only agree when your range starts in row 1.

Always type the 0 at the end. Without it, MATCH uses approximate match, which assumes the column is sorted A to Z and can return a wrong position with no error at all.

=MATCH(G1,B4:B11,0)

Result: 1

1: Harbor Foods is the first entry in B4:B11. The sheet row is 4.

Turn the position into the sheet row

Add the row the range starts on, minus 1. Write it as ROW(B4)-1 instead of typing 3, so the formula still works if someone inserts a row above the table and the data moves to row 5: the reference shifts and ROW follows it.

Another way is to match against the whole column, =MATCH(G1,B:B,0), because then position and row are the same thing. It returns 4 here too. The catch is that it also searches the title and header rows, so if the value you look for also appears above the table, as a header or a note, you get that row instead.

=MATCH(G1,B4:B11,0)+ROW(B4)-1

Result: 4

4: position 1 plus the 3 rows above the data. This is the row number shown at the left of the sheet.

No offset to maintain: ROW of INDEX

INDEX usually looks like it returns a value, but it actually returns a reference to a cell. ROW can read the row number of that reference. So INDEX(B4:B11,MATCH(G1,B4:B11,0)) points at the matching cell, B4, and ROW turns it into 4, with no "+ROW(B4)-1" to get right.

It is the version to use when the range is a named range or a table column whose start you do not want to hard-code. It works in every version of Excel. Swap ROW for COLUMN to get the column number of a match in a header row, as in =COLUMN(INDEX(A3:D3,MATCH("Amount",A3:D3,0))), which returns 4 for column D.

=ROW(INDEX(B4:B11,MATCH(G1,B4:B11,0)))

Result: 4

4, the sheet row of the first Harbor Foods order, the same answer as the offset version.

XMATCH, and the last occurrence (Excel 365 and 2021)

XMATCH is the modern MATCH. Its default is an exact match, so forgetting the third argument cannot silently give a wrong answer, and its fourth argument sets the search direction. With -1 it searches from the bottom up, which gives the last occurrence. That is the most recent order when the log is in date order.

The result is still a position: Harbor Foods' last order is the 8th entry. Add the same ROW(B4)-1 offset to get row 11.

In Excel 2019 and earlier there is no XMATCH. =SUMPRODUCT(MAX((B4:B11=G1)*ROW(B4:B11))) returns 11 as well: the comparison is 1 on matching rows and 0 elsewhere, so multiplying by ROW keeps only the matching row numbers and MAX picks the largest. It returns 0 rather than #N/A when nothing matches, so test for 0 before you use it.

=XMATCH(G1,B4:B11,0,-1)+ROW(B4)-1

Result: 11

11: SO-2208 in row 11 is the last Harbor Foods order. XMATCH without the -1 would give row 4.

Every row number with FILTER and ROW

ROW(B4:B11) returns the row numbers 4 to 11 as a list. FILTER keeps the ones where the customer matches, so you get every matching row, already as sheet rows, with no offset to add. The result spills down, one row number per cell. Leave empty cells below it or you get #SPILL!.

Look at the result: 4, 9 and 11, but not 7. Row 7 holds "Harbor Foods " with a trailing space, so it does not equal G1. This is the reason most "it's right there but Excel can't find it" cases happen. Compare against TRIM(B4:B11) instead and row 7 is included: 4, 7, 9 and 11. Better still, clean the column once with TRIM so every formula agrees.

To show the list in one cell, wrap it: =TEXTJOIN(", ",TRUE,FILTER(ROW(B4:B11),B4:B11=G1)) gives "4, 9, 11". For the 2nd match only, use =INDEX(FILTER(ROW(B4:B11),B4:B11=G1),2), which returns 9.

=FILTER(ROW(B4:B11),B4:B11=G1)

Result: spills 3 rows × 1 column

4
9
11

4, 9 and 11 spill down three cells. Row 7 is missing because of its trailing space.

Handle #N/A when the value is not there

MATCH and XMATCH return #N/A when nothing matches, and the error passes through the +ROW(B4)-1 part. For a value that is genuinely missing, catch it with IFNA and show a message. IFNA only catches #N/A, so a typo in the formula that causes #VALUE! or #REF! still shows up. IFERROR would hide those too.

FILTER has its own third argument for this: =FILTER(ROW(B4:B11),B4:B11="Acme","None") shows None instead of #CALC!.

Before you blame the data, check the usual causes: a trailing space like row 7, a number stored as text in one place and as a number in the other, or a lookup cell that contains something slightly different. Matching is not case-sensitive, so "harbor foods" finds Harbor Foods; for a case-sensitive row, use =XMATCH(TRUE,EXACT(B4:B11,G1))+ROW(B4)-1.

=IFNA(MATCH("Acme",B4:B11,0)+ROW(B4)-1,"Not found")

Result: Not found

Not found: there is no Acme in the customer column. Without IFNA the cell shows #N/A.

Which method to pick

To feed INDEX, use the plain MATCH position with no offset. To report the sheet row of the first match, MATCH(...,0)+ROW(first cell)-1 works in every version. For the last match in Excel 365 or 2021, XMATCH with -1; in older versions, the SUMPRODUCT and MAX formula. For every match, FILTER(ROW()). If you only need the value from that row, skip the row number and use XLOOKUP or INDEX and MATCH directly.

Common mistakes

Reading MATCH's result as the sheet row

MATCH counts from the top of the range you give it. Add ROW(first cell)-1, or the row numbers will be off by the number of rows above the data.

Leaving out the 0 in MATCH

MATCH(G1,B4:B11) uses approximate match on unsorted data and can return a wrong row with no error. Always use MATCH(G1,B4:B11,0), or XMATCH, which is exact by default.

Typing the offset as a number

+3 breaks when someone inserts a row above the table. Use ROW(B4)-1 so the offset moves with the data.

A match "missing" from the results

Usually a stray space or a number stored as text. Compare against TRIM(range) or clean the column, and check with =LEN(B7) for hidden characters.

FAQ

How do I return the row number of a match in Excel?

Use =MATCH(value,range,0)+ROW(first cell of range)-1. MATCH gives the position in the range and the offset turns it into the sheet row. If the range starts in row 1, MATCH alone is the row.

How do I find the row number of the last occurrence of a value?

In Excel 365 or 2021, =XMATCH(value,range,0,-1)+ROW(first cell)-1 searches from the bottom. In older versions use =SUMPRODUCT(MAX((range=value)*ROW(range))).

How do I get all row numbers that match a value?

Use =FILTER(ROW(B4:B11),B4:B11=G1) in Excel 365 or 2021. It spills one row number per match. Wrap it in TEXTJOIN to list them in one cell.

What is the difference between MATCH and ROW in Excel?

MATCH searches for a value and returns its position in a range. ROW takes a cell reference and returns its sheet row number. Combine them to turn a match into a row number.

How do I find the row number based on two criteria?

Multiply the conditions and match the 1: =MATCH(1,(B4:B11=G1)*(C4:C11="North"),0)+ROW(B4)-1 returns 9 here. In Excel 2019 and earlier, confirm it with Ctrl+Shift+Enter.

Functions used

Related guides

Updated