ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   error routine (https://www.excelbanter.com/excel-programming/373278-error-routine.html)

Janis

error routine
 
Thanks for this error handler macro. I have one question about it. It is
for a user form.
Where it says "exit sub" , what is the exit sub for? The end sub is the end
of the subrouting which it reaches if there is no error, but if there is an
error doesn't it go to the error handler? so why does it exit the sub?
Thanks,


Private Sub CommandButton1_click()

on Error goto ErrHandler

Code
xxxxxxx

Exit Sub

ErrHandler:
Select Case Err.Number
Case 9
resume
Case Else
MsgBox Err.Number & " " & Err.Description
End Select
End Sub

Bob Phillips

error routine
 
So that it doesn't drop into the error handler by defaulter even though
there is no error.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Janis" wrote in message
...
Thanks for this error handler macro. I have one question about it. It is
for a user form.
Where it says "exit sub" , what is the exit sub for? The end sub is the

end
of the subrouting which it reaches if there is no error, but if there is

an
error doesn't it go to the error handler? so why does it exit the sub?
Thanks,


Private Sub CommandButton1_click()

on Error goto ErrHandler

Code
xxxxxxx

Exit Sub

ErrHandler:
Select Case Err.Number
Case 9
resume
Case Else
MsgBox Err.Number & " " & Err.Description
End Select
End Sub




Tom Ogilvy

error routine
 
The exit sub is so it doesn't go through the error handler when there is no
error.

Errhandler:

is just a label that is jumped to if an error occurs - it doesn't mark the
end of the "good" code. If you don't have the exit sub, the code will
always pass through the error handler.

--
Regards,
Tom Ogilvy

"Janis" wrote in message
...
Thanks for this error handler macro. I have one question about it. It is
for a user form.
Where it says "exit sub" , what is the exit sub for? The end sub is the
end
of the subrouting which it reaches if there is no error, but if there is
an
error doesn't it go to the error handler? so why does it exit the sub?
Thanks,


Private Sub CommandButton1_click()

on Error goto ErrHandler

Code
xxxxxxx

Exit Sub

ErrHandler:
Select Case Err.Number
Case 9
resume
Case Else
MsgBox Err.Number & " " & Err.Description
End Select
End Sub





All times are GMT +1. The time now is 09:52 PM.

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