Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel find macro error 1

Status
Not open for further replies.

sahmiele

Technical User
Sep 9, 2003
67
US
I am running a simple find macro. I can't seem to figure out how to program around the error that comes up if the value that is searched for is not found. Here is the chunk of code. Thanks in advance!


Selection.Find(What:="MY SEARCH VALUE", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
 
Try something like this:
Code:
Dim FoundRng As Range

   Set FoundRng = Selection.Find(What:="MY SEARCH VALUE", After:=ActiveCell, LookIn:= _
        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False)
   If FoundRng Is Nothing Then
     MsgBox "Search string not found"
   Else
     FoundRng.Activate
   End If


Regards,
Mike
 
Perfect! Thanks for the lightning fast response!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top