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.
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>
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: