PDA

View Full Version : Solved: Help with Find function VBA



webbynet
07-10-2010, 05:10 PM
I am trying to use a find within a Macro but the issue is that my find will constantly change. I have the following example code:

SearchItem = Range("K1")

Columns("J:J").Select
Selection.find(What:=SearchItem, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate

Once I have activated I may want to remove the entire row so the value in cell K1 will change and the new value in K1 is what I would then want to find.

Thank you for your help

brettdj
07-11-2010, 01:02 AM
That will still be fine though as long as you pass the value from K1 to your Find rather than re-use the value within the same code run

Plus you can avoid the Select, and the potential error on no match like this

Cheers

DaveSub Redo()
Dim strSearch As String
Dim rng1 As Range
strSearch = Range("K1").Value
Set rng1 = Columns("J:J").Find(What:=strSearch, After:=[j1], LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If Not rng1 Is Nothing Then
'do something
Else
MsgBox "No match!"
End If
End Sub

webbynet
07-11-2010, 08:51 AM
Thanks Dave, that is spot on for what I needed