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

  • Thread starter Thread starter houston city
  • Start date Start date
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.
 
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.
 
Hi
one way:
msgbox application.match("1-A54",Range("A1:A1000"),0)

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