# MS Excel-find row # containing text

**URL:** https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411
**Category:** Factual Questions
**Created:** [July 21, 2010, 1:06am UTC](https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411 "2010-07-21T01:06:00Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![rbroome](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rbroome](https://boards.straightdope.com/u/rbroome)
#### Post date: [July 21, 2010, 1:06am UTC](https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411/1 "2010-07-21T01:06:00Z")

</div>

I have an Excel spreadsheet page that contains a text string in a certain row. I know the column, but the row can change.  
I need a non-VBA method of searching through the page and finding the row # of the row containing that string.  
Col A  
1  
2  
3  
4  
ODC  
6  
7

what is the command that will scan through col A and locate the row number (5) of the row containing ODC?

this can’t use VBA. It needs to run on PCs, Mac, and with OpenOffice.  
Thanks

---

<div class="post-metadata">

### Author: ![Larry\_Mudd](https://avatars.discourse-cdn.com/v4/letter/l/f14d63/32.png) [@Larry\_Mudd](https://boards.straightdope.com/u/Larry_Mudd)
#### Post date: [July 21, 2010, 2:25am UTC](https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411/2 "2010-07-21T02:25:47Z")

</div>

Will this text only appear in one row?

If so, here’s an easy-peasy kludge:

Make a column that duplicates the row numbers. (I’d just make row 1 “1”, and then each one after [(Cell above)+1] - that way you can paste/page-down until you get to the bottom of your sheet.)

If your row number column is column S, then =SUMIF(A:A,“ODC”,S:S) will give you the row number that your string appears in.

Of course, totally useless if your string appears more than once.

---

<div class="post-metadata">

### Author: ![Bobalude](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@Bobalude](https://boards.straightdope.com/u/Bobalude)
#### Post date: [July 21, 2010, 4:32am UTC](https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411/3 "2010-07-21T04:32:10Z")

</div>

if the string you are searching for is always the same:

in the next column over (assuming your numbers are in column A and column B is blank for scratch space)

=IF(A1=“ODC”,ROW(B1),0)

=IF(A2=“ODC”,ROW(B2),0)

=IF(A3=“ODC”,ROW(B3),0)

and then in empty cells like C1 and C2, you can use:

=max(B:B)  
=min(B:B)

if there is more than one instance of your string, the min/max should be different and you would know to investigate further.

---

<div class="post-metadata">

### Author: ![penultima\_thule](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/penultima_thule/32/3833_2.png) [@penultima\_thule](https://boards.straightdope.com/u/penultima_thule)
#### Post date: [July 21, 2010, 6:04am UTC](https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411/4 "2010-07-21T06:04:24Z")

</div>

Another method if your string is unique.  
Finds first instance if it’s duplicated  
Put the search string into cell A1

Row Col A Col B  
1 ocd =VLOOKUP(A1,$A$2:$B$6,2,FALSE)  
2 qwe =ROW()  
3 asd =ROW()  
4 zxc =ROW()  
5 ocd =ROW()  
6 ert =ROW()

---

<div class="post-metadata">

### Author: ![rbroome](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rbroome](https://boards.straightdope.com/u/rbroome)
#### Post date: [July 21, 2010, 12:01pm UTC](https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411/5 "2010-07-21T12:01:38Z")

</div>

> [@rbroome](#):
>
> I have an Excel spreadsheet page that contains a text string in a certain row. I know the column, but the row can change.  
> I need a non-VBA method of searching through the page and finding the row # of the row containing that string.  
> Col A  
> 1  
> 2  
> 3  
> 4  
> ODC  
> 6  
> 7
> 
> what is the command that will scan through col A and locate the row number (5) of the row containing ODC?
> 
> this can’t use VBA. It needs to run on PCs, Mac, and with OpenOffice.  
> Thanks

Thanks all!

I appreciate this. I still struggle to understand vlookup, but this fragment shows how I can get the job done.

---

<div class="post-metadata">

### Author: ![Chessic\_Sense](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@Chessic\_Sense](https://boards.straightdope.com/u/Chessic_Sense)
#### Post date: [July 21, 2010, 2:45pm UTC](https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411/6 "2010-07-21T14:45:03Z")

</div>

I’d just put my values in the A column and make the B column numbered:

asg 1  
fga 2  
vae 3  
ODC 4  
gag 5  
cvr 6  
vra 7

Then I’d put =VLOOKUP(“ODC”, A1:B22, 2, FALSE). It looks for ODC and returns the second column over. So it returns “4” in this case.

---

<div class="post-metadata">

### Author: ![Chessic\_Sense](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@Chessic\_Sense](https://boards.straightdope.com/u/Chessic_Sense)
#### Post date: [July 21, 2010, 2:48pm UTC](https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411/7 "2010-07-21T14:48:49Z")

</div>

Think of VLOOKUP as searching a phone book. You have a name, but you want the phone number. So do you scan the phone numbers? No, you search the names. Then, when you find the name, you slide over a certain number of columns to the phone number.

If you were a VLOOKUP formula, you’d be =VLOOKUP(“Jones, Martha”, PhoneBook, PhoneNumber, FALSE). This says “Look for Martha Jones in the Phone Book and read me the phone number you find there.” The TRUE and FALSE on the end just tell it whether you want an exact match or a close enough match.

Does that help?

---

<div class="post-metadata">

### Author: ![jcpkeenan](https://avatars.discourse-cdn.com/v4/letter/j/8c91f0/32.png) [@jcpkeenan](https://boards.straightdope.com/u/jcpkeenan)
#### Post date: [December 16, 2015, 6:59pm UTC](https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411/8 "2015-12-16T18:59:54Z")

</div>

I know this is an old thread, but after looking here for a solution, I realized there’s an easier solution to all this… posting in case someone else is looking for the same thing:

Using the MATCH function makes this much easier. If you have, say:

A3 1  
A4 2  
A5 3  
A6 ODC  
A7 5  
etc…

you can enter this formula into any cell:

=MATCH(“ODC”,A3:An,0)

where n is the last row in the array. You will get the relative number of the row in which the string appears, in this case 4. If you wanted the absolute row number (i.e. 6 for A6), you could either start with A1 in the match formula, or add 2 to the result.

Cheers

---

<div class="post-metadata">

### Author: ![CookingWithGas](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cookingwithgas/32/485_2.png) [@CookingWithGas](https://boards.straightdope.com/u/CookingWithGas)
#### Post date: [December 17, 2015, 4:18am UTC](https://boards.straightdope.com/t/ms-excel-find-row-containing-text/547411/9 "2015-12-17T04:18:15Z")

</div>

> [@jcpkeenan](#):
>
> Using the MATCH function makes this much easier.

Absolutely. I am amazed that nobody offered that back in 2010. By far the superior solution. Therefore worth reviving a zombie.
