Deleting shape series and trendlines

  • Thread starter Thread starter Mika
  • Start date Start date
M

Mika

I'm trying to delete all 20 series and trendlines of a shape. My code
doesn't delete them. What is going wrong?

ActiveSheet.ChartObjects("Shape 1").Activate

For i = 1 To 20
Err.Clear
ActiveChart.SeriesCollection(1).Delete
Err.Clear
Next i

Thanks,
Mika
 
Seems like it would be easier to cut the chart and start over but try this

Sub deleteseries()
ActiveSheet.ChartObjects("Chart 1").Activate
On Error Resume Next
For i = 20 To 1 Step -1
ActiveChart.SeriesCollection(i).Delete
Next
End Sub
 
Here's another if you only have ONE chart and you don't know how many series
to start with
Sub deleteseriescount()
ActiveSheet.ChartObjects(1).Activate
x = ActiveChart.SeriesCollection.Count
For i = x To 1 Step -1
ActiveChart.SeriesCollection(i).Delete
Next
End Sub
 
If you don't know how many series, use this. Also, no need to activate
the chart.

Sub DeleteSeries()
With ActiveSheet.ChartObjects(1).Chart.SeriesCollection
Do Until .Count = 0
.Item(1).Delete
Loop
End With
End Sub

If the chart is already active, use this:

Sub DeleteSeries()
With ActiveChart.SeriesCollection
Do Until .Count = 0
.Item(1).Delete
Loop
End With
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
It's great when you have THE charting expert around. Thanks Jon
 

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

Back
Top