Does 'On Error Resume Next' reset error?
Results 1 to 2 of 2

Thread: Does 'On Error Resume Next' reset error?
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Sep 2010
    Posts
    609
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Does 'On Error Resume Next' reset error?

    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:
    Sub A()
    
        For i = 1 To 10
        
            On Error Resume Next
            
            ' Other code here
        
        Next I
    
    End Sub


    Code:
    Sub B()
        
        On Error Resume Next
    
        For i = 1 To 10
            
            ' Other code here
            
            If Err.Number <> 0 Then Err.Clear
        
        Next I
    
    End Sub
    
    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

    Last edited by cr731; Aug 5th, 2019 at 12:48 PM.

  2. #2
    MrExcel MVP shg's Avatar
    Join Date
    May 2008
    Location
    The Great State of Texas
    Posts
    21,603
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    14 Thread(s)

    Default Re: Does 'On Error Resume Next' reset error?

    It does, but I would use Sub B just because it makes clear what the code is doing.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •