On Error Resume Next

Engineer Joe

Well-known Member
Joined
Jun 10, 2005
Messages
549
For some reason, my On Error Resume Next isn't working for one of my macros. It doesn't resume next, but pops up the debug screen. anyone have an idea of why? I've checked and err.number = 0 going into the statement. It throws a 1004, which i've always been able to resume next afterwards. i'm not sure why it's doing it now.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi Joe

This usually happens when you forgot to use Resume to finish the error handling code.

I don't know if this is the case but this is a simple example that illustrates the problem:

Code:
Sub TestErr()
 
On Error GoTo ErrH:
MsgBox 1 / 0
 
Back1:
On Error Resume Next
MsgBox 1 / 0
Exit Sub
 
ErrH:
' do something
GoTo Back1
'Resume Back1
End Sub

In this case with the first #DIV/0 error the code goes back without finishing the error handling code. On the second #DIV/0 error the debug box is displayed even with the "On Error Resume Next" statement.

Now comment the "GoTo Back1" statement and uncomment the "Resume Back1". Now the after the first #DIV/0 error the code goes back after finishing the error handling code. On the second #DIV/0 error the code resumes on the next instruction as you want.

As I said I'm not sure this is the case but I hope it will help.
 
Upvote 0
yes. it only happens if an error has previously been thrown in the code. I thought that if an error is cleared though, that it goes back to 0 and you could use a resume next statement and everyone would be happy. so sometimes i don't handle errors, i just say resume next and then say on error goto 0, which i thought reset it. i'll piddle with it.
 
Upvote 0
I thought that if an error is cleared though, that it goes back to 0 and you could use a resume next statement and everyone would be happy.

If you use the Resume statement then the error handler is desactivated and everyone will be happy. Just remember to clear the error value.

This is not the case. I think you should look for:

- an error situation where you forgot to use the Resume statement. This will mean that the error handler will continue to be active even after you dealt with the error. This would be a case of a missing Resume.

OR

- a error situation where you forgot to enable an error handler.

Ex:

Code:
On Error Resume Next
MsgBox 1 / 0
On Error GoTo 0
 
MsgBox 1 / 0

The "On Error GoTo 0" disables the error handler and so on the second 1/0 you will see the debug error box (you forgot the "On Error Resume Next" after the "On Error GoTo 0", to re-enable the error handler).

In this case you should use the "On Error GoTo 0" only after the second error to keep the error handler enabled during the 2 operations. You should just test and clear the error value.
.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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