ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error Handlers (https://www.excelbanter.com/excel-programming/339220-error-handlers.html)

JohnUK

Error Handlers
 
Can you have more than one ErrorHandlers within the same code?
If you can - How
If not, is there anything else I can do?
I thought it might have been as easy as ErrorHandler and adding a one on the
end, second with adding a two on the end etc, but alas it failed miserably.
Below is the only one that would work (being the only one within the code)

On Error GoTo ErrorHandler
'Code
ErrorHandler:
MsgBox "You have an error" & vbNewLine & _
" ", , " ERROR"

Many thanks to Peter Rooney for his help on my last problem

Gareth[_6_]

Error Handlers
 
Hi John,

You certainly can - I don't know why your previous attempt didn't work.
Try something like:

Sub Foo()

On Error goto ErrorHandler_Date
' code to get date from user

On Error goto ErrorHandler_Number
' code to get number from user


On Error Goto 0

'Skip the error handlers
Exit Sub

ErrorHandler_Date:
MsgBox "Please enter a date"
exit sub

ErrorHandler_Number:
MsgBox "Please enter a date"
exit sub

End Sub

JohnUK wrote:
Can you have more than one ErrorHandlers within the same code?
If you can - How
If not, is there anything else I can do?
I thought it might have been as easy as ErrorHandler and adding a one on the
end, second with adding a two on the end etc, but alas it failed miserably.
Below is the only one that would work (being the only one within the code)

On Error GoTo ErrorHandler
'Code
ErrorHandler:
MsgBox "You have an error" & vbNewLine & _
" ", , " ERROR"

Many thanks to Peter Rooney for his help on my last problem


JE McGimpsey

Error Handlers
 
One way:

Public Sub foo()
On Error GoTo Error_Handler1
'code here
On Error GoTo Error_Handler2
'more code here
Exit_Sub:
Exit Sub
Error_Handler1:
'Handle error
Resume Exit_Sub
Error_Handler2:
'Handle error 2
Resume Exit_Sub
End Sub




In article ,
JohnUK wrote:

Can you have more than one ErrorHandlers within the same code?
If you can - How
If not, is there anything else I can do?
I thought it might have been as easy as ErrorHandler and adding a one on the
end, second with adding a two on the end etc, but alas it failed miserably.
Below is the only one that would work (being the only one within the code)

On Error GoTo ErrorHandler
'Code
ErrorHandler:
MsgBox "You have an error" & vbNewLine & _
" ", , " ERROR"

Many thanks to Peter Rooney for his help on my last problem



All times are GMT +1. The time now is 11:36 PM.

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