Lifetime of On Error Resume Next

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,395
How long does On Error Resume Next last?

I thought it lasts until the end but according to this example, it doesn't.

Module1:

Code:
Option Explicit

Sub A()

On Error Resume Next

    Dim aa
    
    aa = 1 / 0
    
    Call Module2.b

End Sub

Module2:

Code:
Option Explicit

Sub b()

    Dim bb
    
    bb = 1 / 0
    
    Call Module3.c

End Sub

Module3:

Code:
Option Explicit

Sub c()

    Dim cc
    
    cc = 1 / 0

End Sub

Running Sub A, the code stops after Sub 2 is run. It never gets to Sub C.

Why is that?

Thanks
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,723
I believe your error condition changes/ends when U leave any sub or when U change the error condition within the same sub. So U would have to add On error resume next to sub2 if U want it to continue on after an error in Sub2. HTH. Dave
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows
How long does On Error Resume Next last?
It lasts until the procedure in which this statement is used has finished.
The procedure in which the On Error statement is used catches the error, even when other procedures are called.
FYI, it's not VBA specific, error trapping mechanisms in other languages behave the same.
EDIT:
Since you don't have a custom error handler in your procedure, the next line of code is executed (as intended), ie the End Sub line in your Sub A() example.
 
Last edited:

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows
You're welcome!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,980
Messages
5,599,160
Members
414,295
Latest member
Dolenhil

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
Top