Multiple error handling

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,080
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
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,178
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Yes, and remove the OEG0 line.
 

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,080
Why?

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

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,178
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Because that will disable your error handler and any further errors won't be handled.
 

Forum statistics

Threads
1,078,252
Messages
5,339,097
Members
399,277
Latest member
Jyoti C

Some videos you may like

This Week's Hot Topics

Top