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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Check within Find - Excel VBA

Status
Not open for further replies.

dar149

MIS
Mar 5, 2002
117
US
I am searching for a specific text item, but if the item is not found I receive error 91. I have tried unsuccessfully to put in error checking before or after the find, but it still gets a runtime error when the item is not found. Following is the error checking code and the find statement. Any suggestions??

'Check for likely Automation errors.
If Err.Number = 91 Then
' Tell user what happened. Then clear the Err object.
msg = "Error Message!"
MsgBox msg, , "No Match"
Err.Clear ' Clear Err object fields
End If

Cells.Find(What:=compval, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

Once the message box is displayed, when the user clicks OK, I want to go to a specific part of the macro.

Any suggestions would be appreciated...

Debbie
 
Don't do a .Activate. Set a range object instead. Then test the range object for Nothing.
Code:
Set MyRange = Cells.Find(What:=compval, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False)

If MyRange Is Nothing Then
'error trap stuff
End If
Hope this helps :)

Skip,
Skip@TheOfficeExperts.com
 
This worked... Thanks for the information!

Debbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top