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