G
Guest
I have a macro which amoung other things changes the name and values of an
embedded chart. When I run the macro for the first time everything works as
intended. If I rerun the macro, an error occurs at the .name statement. If
I comment out that line, everything else works fine. The same thing happens
if I have saved the file (after the error has occured once), and then re-open
the file and try to run the macro. The error message is
Run time error '1004':
Unable to set the Name property of the series class
Once the error has occured, the macro will never work correctly again unless
I create a new chart, and change the chart name in the macro. If I do this
the macro will work once, and upon subsequent running of the macro, the .name
error will occur.
The section of the code involved is:
k=1
While stock(k) <> ""
Sheets("Plot Period").Select
ActiveSheet.ChartObjects("Chart 14").Activate
With ActiveChart.SeriesCollection(k)
.Name = stock(k) 'this is the statement that causes the error
.XValues = "='" + stock(k) + "'!" + daterange
.Values = "='" + stock(k) + "'!" + gainrange
End With
k = k + 1
I have tried other forms of the code, with no success.
embedded chart. When I run the macro for the first time everything works as
intended. If I rerun the macro, an error occurs at the .name statement. If
I comment out that line, everything else works fine. The same thing happens
if I have saved the file (after the error has occured once), and then re-open
the file and try to run the macro. The error message is
Run time error '1004':
Unable to set the Name property of the series class
Once the error has occured, the macro will never work correctly again unless
I create a new chart, and change the chart name in the macro. If I do this
the macro will work once, and upon subsequent running of the macro, the .name
error will occur.
The section of the code involved is:
k=1
While stock(k) <> ""
Sheets("Plot Period").Select
ActiveSheet.ChartObjects("Chart 14").Activate
With ActiveChart.SeriesCollection(k)
.Name = stock(k) 'this is the statement that causes the error
.XValues = "='" + stock(k) + "'!" + daterange
.Values = "='" + stock(k) + "'!" + gainrange
End With
k = k + 1
I have tried other forms of the code, with no success.