Query with Excel VBA Find Method
I have used cdo---loop instead of while---wend
try tis mdoified macro
Sub test()
Dim rngpo As Range
Dim strpo As String
Dim add As String
strpo = "a" ' this is only an example
With ActiveSheet.Range("K1:K5000")
Set rngpo = .Find(strpo, After:=Cells(1, 11), _
LookIn:=xlValues, lookat:=xlWhole)
add = rngpo.Address
rngpo.Select
'Code to process each occurrence
Do
Set rngpo = .FindNext(rngpo)
If rngpo.Address = add Then GoTo line1
rngpo.Select
Loop While Not (IsEmpty(rngpo)) And rngpo.Address <
add
line1:
End With
End Sub
=================================================
MarkM wrote:
Hello,
I have the following code that searches for a particular string in
column K and repeats the process until all have been found (or that's
what I intended).
In one workbook, the first instance is found at K330 with the next 8
rows containing the same value.
The address of rngPO changes after each find and after the last one
the address of rngPO changes back to K330.
Could someone please advise how I can overcome this issue?
With ActiveSheet.Range("K1:K5000")
Set rngPO = .Find(strPO, After:=Cells(1,11),
LookIn:=xlValues)
While Not (IsEmpty(rngPO))
rngPO.Select
Code to process each occurrence
Set rngPO = .FindNext(rngPO)
Wend
End With
Thank you
Mark
|