Why this nested error handler works?

telesien

New Member
Joined
May 25, 2016
Messages
35
Hi, I tried to nest error handler within an error handler, which as I found out is not really possible.

However I did manage to find solution, which made it work, but without explanation how and why. I don't want to blindly use codes, even though they do work for me.

Can someone please explain to me, why this workaround works?

Code:
On Error GoTo Errorhandler
*code

Errorhandler:
*code

[COLOR=#ff0000]Resume Error

Error:[/COLOR]
On Error GoTo Errorhandler2

The key lines are the red ones. Without them it would be just nesting error handler into error handler, which doesn't work and you get the usual VBA error message instead of progressing to second error handler.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
The Resume statement resets the current exception state, which is what then allows you to set a new error handler correctly. See here: On Error WTF? | Excel Matters
 
Last edited:
Upvote 0
Ah, so "on error" is more of a on/off switch than simple redirect. Now it makes sense. As you can see I lack any formal coding or programming background, so I have to work with analogies :)

I guess that while the above mentioned code works, it is probably way too messy solution or professionals.

Thanks for the answer :)
 
Upvote 0
No, On Error is a redirect. But once you have raised an error, you have to reset that error state before any other errors can be handled. To do that, you want a Resume statement.
 
Upvote 0

Forum statistics

Threads
1,213,496
Messages
6,113,993
Members
448,539
Latest member
alex78

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