how to find row with a given value in a column

  • Thread starter Thread starter rtos
  • Start date Start date
R

rtos

Hello ,
I am trying to do following in vba

name value
a 1
b 2
c 3

I know the name value , how do I find whats the row number where the
name='a'.

thx
ray
 
Hi

This is a example with a inputbox
Use the commented line if you want to select the cell

Sub Find_First()
Dim FindString As String
Dim Rng As Range
FindString = InputBox("Enter a Search value")
If Trim(FindString) <> "" Then
Set Rng = Range("A:A").Find(What:=FindString, _
After:=Range("A" & Rows.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
'If Not Rng Is Nothing Then Application.Goto Rng, True
If Not Rng Is Nothing Then MsgBox Rng.Row
End If
End Sub
 
one way
sub findrow()
msgbox columns(1).find("a").row
end sub
 

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

Back
Top