Multiple error handling

tiredofit

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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,177
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,208
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,177
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
Because that will disable your error handler and any further errors won't be handled.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,858
Messages
5,489,304
Members
407,686
Latest member
Chuck1960

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top