+ Reply to Thread
Results 1 to 3 of 3

Thread: looping in the find command

  1. #1
    Registered User
    Join Date
    05-16-2009
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    2

    looping in the find command

    I am trying to provide a search string and then loop round searching for this search string until the beginning find cell is found again however I am having problems making my code work - here it is:
    Sub searchname()
    '
    ' searchname Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+C
    '
    
    ' An input box used to place a value into a variable
        Dim strMessage As String
        Dim actadd2 As String
        
        strMessage = InputBox("Please enter what you wish to search for:")
        strMessage = strMessage
        MsgBox "This is what you entered " & strMessage
        
        
            Cells.Find(What:=strMessage, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
        
        'Cells.FindNext(After:=ActiveCell).Activate
        
        If Not ActiveCell Is Nothing Then
        MsgBox (ActiveCell)
        actadd2 = ActiveCell.Address
        MsgBox (actadd2)
        Do
                 
             Cells.FindNext(After:=ActiveCell).Activate
    
        Loop While Not ActiveCell Is Nothing And ActiveCell.Address <> actadd2
        End If
    
    End Sub
    Many Thanks
    Last edited by Leith Ross; 05-16-2009 at 05:02 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    re: looping in the find command

    Hello jmgriffin101,

    I made the necessary changes for you. It will stop now when you loop back to the start of the search.
    Sub searchname()
    '
    ' searchname Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+C
    '
    
    ' An input box used to place a value into a variable
        Dim FirstAddx As String
        Dim strMessage As String
        Dim actadd2 As String
        Dim Result As Range
        
        strMessage = InputBox("Please enter what you wish to search for:")
        strMessage = strMessage
        MsgBox "This is what you entered " & strMessage
        
        Set Result = Cells.Find(What:=strMessage, After:=[A1], _
                     LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
                     SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        
        If Not Result Is Nothing Then
           FirstAddx = Result.Address
           MsgBox Result.Value
             Do
               Result.Activate
               MsgBox Result.Value
               Set Result = Cells.FindNext(Result)
             Loop While Not Result Is Nothing And Result.Address <> FirstAddx
        End If
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    05-16-2009
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: looping in the find command

    Leith,

    First of all thanks for that kind solution you provided - now I can send a working timesheet to my father-in-law in Chile (just a present). I must admit I never knew the power of excel and I did the above timesheet in Access (my father-in-law however doesn't have Access :-( ) however some of the help forums with MS Access were less helpfull and I took longer to solve the problems like multiplying the numeric summed times by 24 - Anyhow my point is this forum and your help was much more helpful and I send my gratitude to you and look forward to communicating again in the future.

    Kind Regards

    James Griffin

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0