Excel 2007: How to loop through a selection of charts?

S

spectrallypure

Hi all! I have the following little code that processes the series in
the active chart:

Sub RemoveOldSeriesInActiveChart()
ActiveChart.SeriesCollection(12).Delete
'(...lots of other similar operations...)
End Sub

The problem is that (obviously) it only works on a single chart. I
need to extend the code to perform those operations not only on the
active chart but on all and each of the selected charts.

So far I haven't been able to find a way of looping through all the
charts in a selection of charts. I was suggested to try the following:

For Each coChartObject In Selection
coChartObject.SeriesCollection(12).Delete
'(etc...)
Next coChartObject

but the given code doesn't work in Excel 2007 (I found the case of a
person with the very same problem:
http://www.pcreview.co.uk/forums/thread-3198875.php). I arrives up to
the second line and gives the error: "Run-time error '438': Object
doesn't support this property or method".

Then I tried the following (adding the '.Chart' part):

For Each coChartObject In Selection
coChartObject.Chart.SeriesCollection(12).Delete
'(etc...)
Next coChartObject

but then execution fails with "Run-time error 1004: - Invalid
parameter"...

Could somebody please give a hint of how to accomplish this?
Thanks in advance for any help! :)

Regards,

Jorge Luis.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top