how to extract the row number of a cell with certain value

H

houston city

Hi, I am trying to extract the row number of a cell with a particular
value. For example, I have a cell with the value '1-A54' in it, and I
am trying to get the row number where this value appear. Can anybody
tell me how to write it in VBA? Thanks a lot.
 
A

Always Learning

Hi There,
Think this will work. Just from memory so please forgive me if I have missed
something.

Dim RowNum As Integer
Dim ColNum as Integer
Dim RowFoundOn as Integer
Dim ImFinished as Boolean

RowNum = 0
ColNum = 1 '*** set to column A, change to the column containing values
you are searching for.
Do
RowNum = RowNum + 1
Cells(RowNum,ColNum).Select
If Cells(RowNum,ColNum).Value = "1-A54"
RowFoundOn = ActiveCell.Row
ImFinished = True
End If
Loop Until ImFinished

All the best,

Steve Wilson.
 
F

Frank Kabel

Hi
one way:
msgbox application.match("1-A54",Range("A1:A1000"),0)

or use the Find method (see VBA help for an example)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top