• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to find the string in the particular Column only

ThrottleWorks

Excel Ninja
Hi,

I am trying to search a string in a particular column only however macro does search the string in entire worksheet.

For example I want to find Range A1 value (or string) in Column C only how should I code it.

I tried selecting Column C before finding but it's not working.

Can anyone please help me in this.
 
You'll want to state what range to do the Find on.
Code:
Sub Example()
Dim fCell As Range
Set fCell = Range("C:C").Find(Range("A1").Value)

If fCell Is Nothing Then
    MsgBox "Nothing found"
Else
    MsgBox fCell.Address
End If
End Sub
 
Hi Luke Sir,

My mistake, I forgot to mention I have to do a partial search. I guess in this case we to have write something else.

For example, range A1 value is yam and column has value as yamaha.
I need to find yamaha on the baseof "yam".

Code:
Set fCell = Range("C1:C65000").Find(rn.Offset(0, -2).Value)
If fCell Is Nothing Then
MsgBox "Nothing found"
Else
MsgBox fCell.Address
End If
 
Modify the operator in the Find method.
Expanded Find method with more operators called out:
Code:
Set fCell = Range("C1:C65000").Find(what:=rn.Offset(0, -2).Value, LookIn:=xlValues, lookat:=xlPart, MatchCase:=False)
 
Good morning Luke Sir,

Thanks a lot for the help. I think I should have tried this before posting. :(

Have a nice day ahead. :)
 
Back
Top