Does 'On Error Resume Next' reset error?

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
I am using On Error Resume Next within a for...next loop, and need to check if an error occurs within each loop. I'm wondering if the On Error Resume Next statement itself clears any existing error?

For example, in Sub A below, the On Error Resume Next statement is inside the loop, versus B, where it's outside the loop but Err.Clear is used to clear any error at the end of the loop.

Code:
[FONT=Verdana]Sub A()
[/FONT]
[FONT=Verdana]    For i = 1 To 10
    
        On Error Resume Next
        
        ' Other code here
    
    Next I
[/FONT]
[FONT=Verdana]End Sub[/FONT]


Code:
[FONT=Verdana]Sub B()
    
    On Error Resume Next
[/FONT]
[FONT=Verdana]    For i = 1 To 10
        
        ' Other code here
        
        If Err.Number <> 0 Then Err.Clear
    
    Next I
[/FONT]
[FONT=Verdana]End Sub
[/FONT]

As far as I can tell, both result in Err.Number being 0 just before "' Other Code here".

Is there any advantage/preference between the two? Note I only care about Err.Number being 0 or not when I am checking for error.

Thanks

<strike></strike>
 
Last edited:

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,779
Office Version
  1. 2010
Platform
  1. Windows
It does, but I would use Sub B just because it makes clear what the code is doing.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,736
Messages
5,597,815
Members
414,178
Latest member
Octavian Manoli

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