Thanks Thanks:  0
Likes Likes:  0
Results 1 to 7 of 7

Thread: Multiple error handling

  1. #1
    Board Regular
    Join Date
    Apr 2013
    Posts
    812
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Multiple error handling

    I have added an error handling in the code below.

    Suppose MyArray(10, 1) = #NA, then the error handling works but if MyArray(11, 1) = #NA also, it fails.

    It seems the error handling cannot handle more than one error. How can I fix this? I have even added an On Error GoTo 0 to "reset" it but it still doesn't work.

    Code:
    Dim a As Integer
    
    a = 1
    
    On Error Goto ErrHandler
    
    For b = 1 To 100
    
        Do Until MyArray(a, 1) = 100
    
            a = a + 1
    
        Loop
    
    Continue:
    
    Next b
    
    Exit Sub
    
    ErrHandler:
    
        MsgBox "Error"
    
        On Error GoTo 0
    
        GoTo Continue

  2. #2
    Board Regular
    Join Date
    Apr 2013
    Posts
    812
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Multiple error handling

    Should I have added Resume Continue instead of GoTo continue?

  3. #3
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    32,351
    Post Thanks / Like
    Mentioned
    25 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Multiple error handling

    Yes, and remove the OEG0 line.

  4. #4
    Board Regular
    Join Date
    Apr 2013
    Posts
    812
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Multiple error handling

    Why?

    I thought after setting On Error Something, you should always put On Error GoTo 0 to "reset" it?

  5. #5
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    32,351
    Post Thanks / Like
    Mentioned
    25 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Multiple error handling

    Because that will disable your error handler and any further errors won't be handled.

  6. #6
    Board Regular
    Join Date
    Apr 2013
    Posts
    812
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Multiple error handling

    Thanks

  7. #7
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    32,351
    Post Thanks / Like
    Mentioned
    25 Post(s)
    Tagged
    3 Thread(s)

    Default Re: Multiple error handling

    You may want to skim through this article I wrote recently: On Error WTF? | Excel Matters

Some videos you may like

User Tag List

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
  •