Macro error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If you cancel the inputbox or enter in a invalid name it goes to debug. Here
is the macro I'm using:

Sub SelectSheet()
res = InputBox("Enter employee (sheet) name")
On Error Resume Next
Set sh = Worksheets(res)
On Error GoTo 0
If sh Is Nothing Then
MsgBox res & " isn not a valid sheet name"
Else
sh.Activate
End If
End Sub

Thanks,
Chance
 
In the VBE, go to Tools=>Options and in the General tab make sure you have
selected Break on Unhandled errors instead of Break on All Errors.
 
Break on unhandled errors is selected.

Tom Ogilvy said:
In the VBE, go to Tools=>Options and in the General tab make sure you have
selected Break on Unhandled errors instead of Break on All Errors.
 
My omission

this should do it:

Sub SelectSheet()
Dim sh As Worksheet
res = InputBox("Enter employee (sheet) name")
On Error Resume Next
Set sh = Worksheets(res)
On Error GoTo 0
If sh Is Nothing Then
MsgBox res & " isn not a valid sheet name"
Else
sh.Activate
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top