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:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
It does, but I would use Sub B just because it makes clear what the code is doing.
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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