|
-
Aug 10th, 2012, 06:17 PM
#1
Thread Starter
Lively Member
[RESOLVED] find.next... (??)
Hey all,
Love the new look of the forum, Awesome!
straight to business...
I have a search script that i use to search two spacific columns in exel, the code (below) works well but stops dead when it finds just one search result. i would like it to be able to loop through to find more result IE: "Smith, john - Smith, Jane - Smith Blugh"
I've tried various attempts at: - Selection.FindNext (after:=ActiveCell).activate - and dim ExitLoop as boolean - Exit loop findnext...
but have drawn a blank... any help would be very much appreciated.
Cheers
Code:
Private Sub Cmd_OK_Click()
Dim MyText As String
Dim MyMsg As String
Dim MyType
Dim MyTitle As String
MyText = txtname.Value
MyText = TxtChange.Value
MyMsg = "No matches were found."
MyType = vbOKOnly + vbExclamation
MyTitle = "No Matches"
On Error GoTo ErrorHandler
Application.Goto Reference:="Name"
Selection.Find(What:=txtname, after:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
If txtname.Value = "" Then
Application.Goto Reference:="CO"
Selection.Find(What:=TxtChange, after:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
If TxtChange.Value = "" Then
Range("A1").End(xlDown).Select
End If
Exit Sub
ErrorHandler:
MsgBox MyMsg, MyType, MyTitle
End If
End Sub
-
Aug 10th, 2012, 11:26 PM
#2
Re: find.next... (??)
Perhaps this will help 
Section 3 has what you are looking for
Topic: .Find and .FindNext In Excel VBA
Link: http://siddharthrout.wordpress.com/2...-in-excel-vba/
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Aug 14th, 2012, 03:30 PM
#3
Thread Starter
Lively Member
Re: find.next... (??)
Thanks koolsid,
but i got lazy and just added in a few:
Code:
Selection.FindNext(After:=ActiveCell).Activate
Messy but does the job...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|