On error goto 0

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,825
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I thought:

Code:
On Error GoTo 0

enables the default error checking behaviour.

If so, why does this fail?

Code:
Sub Errorhandler()

On Error GoTo ErrMsg
X = 12
Y = 20 / 0
Z = 30
Exit Sub

ErrMsg:
MsgBox "There seems to be an error" & vbCrLf & Err.Description


'**********
On Error GoTo 0
'**********


On Error GoTo ErrMsg2
A = 10 / 2
B = 35 / 0
Exit Sub

ErrMsg2:
MsgBox "There seems to be an error again" & vbCrLf & Err.Description

End Sub

but substituting

Code:
On Error GoTo 0

with

Code:
On Error GoTo -1

works.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
The code is not showing "There seems to be an error again"?
 
Upvote 0
The code is not showing "There seems to be an error again"?
Yes

I thought adding On Error GoTo 0 would reset the error handling status and with On Error GoTo ErrMsg2 immediately afterwards, it'll work.
 
Upvote 0
I think that in this case the right thing maybe is -1:
Because when the execution reaches "On Error GoTo ErrMsg 2" there's still an exception occurred before.

 
Upvote 0
Hi tiredofit. Seems like your doing some error learning today. Here's an informative link with other links within that have quite a bit of error learning. HTH. Dave
 
Upvote 0
Hi tiredofit. Seems like your doing some error learning today. Here's an informative link with other links within that have quite a bit of error learning. HTH. Dave
Thanks.

It's all because if this:

 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,089
Members
448,548
Latest member
harryls

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top