Thread: Error Handling
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
todd todd is offline
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.