I'm trying to use the find function to make my macros easier to handle, but I don't know how to run through all instances of what I'm trying to find and then stop. Currently I just have my find function in an infinite loop and it stops when it runs into an error. This works well I guess, but I'd like to know how to stop after the last instance without error. Here's the code that I have been using:
Do
Cells.Find(What:="(", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
'Unimportant code here
Loop
I've done some searches and found some code that checks to see if the find function returns a range. I've tried this method, but because I know nothing about this language, I'm having a hard time figuring out where my code is messing up. Here's the code that I'm trying to code now:
Dim rFound As Range
Do
Set rFound = Cells.Find(What:="(", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
If Not rFound Is Nothing Then
'Unimportant code here
End If
Loop While Not rFound Is Nothing
The code I'm replacing with "'Unimportant code here" has been tested and works fine. The program runs into an error at "Set rFound = ...". Does anybody know what I'm doing wrong?
--dorky
Bookmarks