Results 1 to 3 of 3

Thread: [RESOLVED] find.next... (??)

  1. #1
    Lively Member
    Join Date
    Jan 08
    Posts
    106

    Resolved [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

  2. #2
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,415

    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

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  3. #3
    Lively Member
    Join Date
    Jan 08
    Posts
    106

    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
  •