Lifetime of On Error Resume Next

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,832
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
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
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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
 
Upvote 0
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:
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,166
Members
448,870
Latest member
max_pedreira

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