Multiple error handling

tiredofit

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

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,397
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,226
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
35,397
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS

ADVERTISEMENT

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

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,431
Messages
5,511,305
Members
408,840
Latest member
Hetta SdP

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top