Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Query with Excel VBA Find Method

Option Explicit
Sub testme()

Dim RngToSearch As Range
Dim FirstAddress As String
Dim StrPO As String
Dim RngPO As Range

Set RngToSearch = ActiveSheet.Range("K1:k5000") '(not K:K???)

StrPO = "something"

With RngToSearch
'xlwhole or xlpart????
'it's better to explicitly use all the parms.
'otherwise you inherit the settings from the last Find
'either from the user or code!
Set RngPO = .Cells.Find(what:=StrPO, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
MatchByte:=False)

If RngPO Is Nothing Then
MsgBox "not found!"
Else
FirstAddress = RngPO.Address
Do

'code to process each occurrence
'it's not usually necessary to select this range

'look for more
Set RngPO = .FindNext(after:=RngPO)

If RngPO Is Nothing Then
Exit Do
End If

If RngPO.Address = FirstAddress Then
Exit Do
End If
Loop
End If
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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel VBA : Find Method manfareed Excel Programming 2 January 6th 08 02:28 PM
Excel VBA .Find method - am I clueless? Joe in Australia via OfficeKB.com Excel Programming 1 January 29th 06 11:02 AM
Excel Find Method JonWayne Excel Programming 3 April 7th 05 12:43 PM
Proper method for Excel/Query/Macro reporting Laphan[_2_] Excel Programming 1 October 30th 03 12:59 PM
Problems with Excel Web Query for Post Method URL Brian Excel Programming 0 July 24th 03 03:55 AM


All times are GMT +1. The time now is 10:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"