ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro error (https://www.excelbanter.com/excel-programming/320828-macro-error.html)

Chance224

Macro error
 
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


Tom Ogilvy

Macro error
 
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.

--
Regards,
Tom Ogilvy

"Chance224" wrote in message
...
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




Chance224

Macro error
 
Break on unhandled errors is selected.

"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy

"Chance224" wrote in message
...
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





Tom Ogilvy

Macro error
 
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


--
Regards,
Tom Ogilvy


"Chance224" wrote in message
...
Break on unhandled errors is selected.

"Tom Ogilvy" wrote:

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.

--
Regards,
Tom Ogilvy

"Chance224" wrote in message
...
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








All times are GMT +1. The time now is 12:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com