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:
Many ThanksSub 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
Last edited by Leith Ross; 05-16-2009 at 05:02 PM. Reason: Added Code Tags
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 Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks