Looping Find

  • Thread starter Thread starter pk
  • Start date Start date
P

pk

Hello, I hope someone can help me with this.

Could someone give me some code that will loop as in the
following logic:

do
Find the next cell in column D containing "Red"
Activate the found cell
do something to the found cell
loop until no more are found

Thanks in advance...for your assistance...
 
One way:

If you're modifying the found cell so that it won't continue to be
found:

Dim found As Range
Set found = Columns(4).Find( _
What:="Red", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not found Is Nothing Then
Do
found.Value = found.Value & " Rover"
Set found = Columns(4).FindNext(After:=found)
Loop Until found Is Nothing
End If

If you're not modifying the found cell:

Dim found As Range
Dim foundAddr As String
Set found = Columns(4).Find( _
What:="Red", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not found Is Nothing Then
foundAddr = found.Address
Do
found.Offset(0, 1).Value = "Rover"
Set found = Columns(4).FindNext(After:=found)
Loop Until found.Address = foundAddr
End If

Note that I didn't activate the found cell because it's almost never
necessary.
 
Back
Top