Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Error not trapped - please help!!!

Hi,

I'm going nuts trying to solve the following problem. If I execute the
following code when the active sheet has no named ranges, the first error is
trapped successfully, but the second one does not get trapped and 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, I will
really appreciate your help!

Bura


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error not trapped - please help!!!

Bura,

An alternative approach

Sub MySub()
Dim r As Range
Dim isA As Boolean
Dim isB As Boolean

isA = False
isB = False

On Error Resume Next
Set r = ActiveSheet.Range("AAA")
isA = Not r Is Nothing

Set r = ActiveSheet.Range("BBB")
isB = Not r Is Nothing

On Error GoTo 0

If isA Then
doAStuff
ElseIf isB Then
doBStuff
End If
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bura Tino" wrote in message
...
Hi,

I'm going nuts trying to solve the following problem. If I execute the
following code when the active sheet has no named ranges, the first error

is
trapped successfully, but the second one does not get trapped and 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, I will
really appreciate your help!

Bura




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Error not trapped - please help!!!

You can't have two On Error Goto statements in one routine.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Error not trapped - please help!!!

You can't have two On Error Goto statements in one routine.

Sure you can. You can have as many On Error Goto statements as
you want. It may not be the best way to write the code, but it is
certainly legal.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"chris" wrote in message
...
You can't have two On Error Goto statements in one routine.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Error not trapped - please help!!!

Also, only one On Error statement can be in effect at any one time.

--
Regards,
Tom Ogilvy


"chris" wrote in message
...
You can't have two On Error Goto statements in one routine.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Error not trapped - please help!!!



"Bob Phillips" wrote in message
...
Bura,

An alternative approach

This helped!

Sub MySub()
Dim r As Range
Dim isA As Boolean
Dim isB As Boolean

isA = False
isB = False

On Error Resume Next
Set r = ActiveSheet.Range("AAA")
isA = Not r Is Nothing

Set r = ActiveSheet.Range("BBB")
isB = Not r Is Nothing

On Error GoTo 0

If isA Then
doAStuff
ElseIf isB Then
doBStuff
End If
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bura Tino" wrote in message
...
Hi,

I'm going nuts trying to solve the following problem. If I execute the
following code when the active sheet has no named ranges, the first

error
is
trapped successfully, but the second one does not get trapped and 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, I

will
really appreciate your help!

Bura






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error not trapped - please help!!!

You can actually lose the lines

isA = False
isB = False

because the line

IsA = NOt r Is Nothing will set it to True or False, no need to
initialise
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bura Tino" wrote in message
...


"Bob Phillips" wrote in message
...
Bura,

An alternative approach

This helped!

Sub MySub()
Dim r As Range
Dim isA As Boolean
Dim isB As Boolean

isA = False
isB = False

On Error Resume Next
Set r = ActiveSheet.Range("AAA")
isA = Not r Is Nothing

Set r = ActiveSheet.Range("BBB")
isB = Not r Is Nothing

On Error GoTo 0

If isA Then
doAStuff
ElseIf isB Then
doBStuff
End If
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bura Tino" wrote in message
...
Hi,

I'm going nuts trying to solve the following problem. If I execute the
following code when the active sheet has no named ranges, the first

error
is
trapped successfully, but the second one does not get trapped and 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, I

will
really appreciate your help!

Bura








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error not trapped - please help!!!

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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error not trapped - please help!!!

You should have tried this, you would have seen that it doesn't work.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Pyball " wrote in message
...
The reason the second error is not getting trapped is because the first
error is still in affect. So when the program gets to the second error
trap the program is still in an error condition so it executes the goto
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 execute
the
following code when the active sheet has no named ranges, the first
error is
trapped successfully, but the second one does not get trapped and
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, I
will
really appreciate your help!

Bura *



---
Message posted from http://www.ExcelForum.com/



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 7 March 7th 05 06:29 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 0 February 28th 05 06:26 PM
Can error 1004 be trapped???? Richard m Excel Programming 3 November 29th 03 02:55 PM


All times are GMT +1. The time now is 03:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"