Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Error Handling

I am trying to handle an error for the following code:

For x = 1 To iSeriesCount

iPointsCount = ActiveChart.SeriesCollection
(x).Points.Count
..
.. [other code]
..

10 Next x

The iPointsCount line will cause an error if any of the
series have no points. This is the case for series 1 and
2 (there are 4 series).

I changed the code to this:

For x = 1 To iSeriesCount

On Error Goto 10

iPointsCount = ActiveChart.SeriesCollection
(x).Points.Count
..
.. [other code]
..

10 Next x

This worked when x was 1, but when it went back and x was
2, it gave me the same error and stopped running as
though the On Error line never existed. I made line 10
On Error Goto 0 to turn it off every time it looped (so
it would reset each time). This also failed. I moved
the On Error line above the "For" line and this also
failed.

I don't understand why the error handling works once but
doesn't work the next time. Every time it hits a run-
time error it should go to 10. But it doesn't. By the
way, the code in the middle that I left out doesn't
transfer to any other subroutines or procedures.

I'm baffled with this one.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Error Handling

Todd,

When an error occurs and you have an On Error Goto <label
statement in effect, code execution transfers to that point, but
code is still running in "error handler mode". You need to use a
Resume or Resume <label statement to clear the error status and
transfer execution again. E.g.,

On Error Goto ErrH:
For x = 1 To iSeriesCount
' code
10: Next x
' code
Exit Sub
ErrH:
Resume 10


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





"Todd" wrote in message
...
I am trying to handle an error for the following code:

For x = 1 To iSeriesCount

iPointsCount = ActiveChart.SeriesCollection
(x).Points.Count
.
. [other code]
.

10 Next x

The iPointsCount line will cause an error if any of the
series have no points. This is the case for series 1 and
2 (there are 4 series).

I changed the code to this:

For x = 1 To iSeriesCount

On Error Goto 10

iPointsCount = ActiveChart.SeriesCollection
(x).Points.Count
.
. [other code]
.

10 Next x

This worked when x was 1, but when it went back and x was
2, it gave me the same error and stopped running as
though the On Error line never existed. I made line 10
On Error Goto 0 to turn it off every time it looped (so
it would reset each time). This also failed. I moved
the On Error line above the "For" line and this also
failed.

I don't understand why the error handling works once but
doesn't work the next time. Every time it hits a run-
time error it should go to 10. But it doesn't. By the
way, the code in the middle that I left out doesn't
transfer to any other subroutines or procedures.

I'm baffled with this one.



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
Error Handling Kevin Excel Discussion (Misc queries) 4 June 19th 08 12:31 AM
Handling #NUM! error Michel Khennafi Excel Worksheet Functions 1 February 26th 07 08:49 PM
Error handling Tim C Excel Programming 1 October 7th 03 10:00 PM
Error handling John Pierce Excel Programming 3 October 3rd 03 12:17 PM
Error Handling Bill Lunney Excel Programming 0 August 6th 03 11:56 PM


All times are GMT +1. The time now is 02:05 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"