The reason the second error is not getting trapped is because the firs
error is still in affect. So when the program gets to the second erro
trap the program is still in an error condition so it executes the got
statement.
Try it this way:
Sub MySub()
Dim r as Range
Dim isA as Boolean
Dim isB as Boolean
isA = False
isB = False
TryA:
On Error GoTo TryB
Set r = ActiveSheet.Range("AAA")
isA= True
GoTo Proceed
TryB:
On Error GoTo 0 'This should clear the previous error.
On Error GoTo Proceed
Set r = ActiveSheet.Range("BBB")
isB = True
GoTo Proceed
Proceed:
If isAThen
doAStuff
ElseIf isB Then
doBStuff
End If
End Sub
Bura Tino wrote:
*Hi,
I'm going nuts trying to solve the following problem. If I execut
the
following code when the active sheet has no named ranges, the firs
error is
trapped successfully, but the second one does not get trapped an
the
execution breaks!
Sub MySub()
Dim r as Range
Dim isA as Boolean
Dim isB as Boolean
isA = False
isB = False
TryA:
On Error GoTo TryB
Set r = ActiveSheet.Range("AAA")
isA= True
GoTo Proceed
TryB:
On Error GoTo Proceed
Set r = ActiveSheet.Range("BBB")
isB = True
GoTo Proceed
Proceed:
If isAThen
doAStuff
ElseIf isB Then
doBStuff
End If
End Sub
Perhaps it's invalid to have 2 "On Error" statements? In any case,
will
really appreciate your help!
Bura
--
Message posted from
http://www.ExcelForum.com