Looping

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello there,

Can anyone help me with a code that delets all series in a certain chart? No
matter how many series there are.

Thanks....
 
Public Sub DeleteSeries()

Dim XLChart As Chart, XLSeriesCol As SeriesCollection, XLSeries As Series

Set XLChart = Sheets("SheetName").ChartObjects(1).Chart
' above assumes your chart is the first or only one on the worksheet
Set XLSeriesCol = XLChart.SeriesCollection

For Each XLSeries In XLSeriesCol
XLSeries.Delete
Next XLSeries

Set XLSeriesCol = Nothing
Set XLChart = Nothing

End Sub
 
Thans,

This is what I was looking for, but I cant get it to work.
Set XLChart = Sheets("SheetName").ChartObjects(1).Chart
I replaced the sheetname and chartobject number but It still comes up with
an error.
 
Would help to know the error message, but most likely it is because I wrote
the code assuming a regular worksheet with an embedded chart, you may well
have a chart on its own sheet instead. A chart sheet is already a Chart
object so you don't need to refer to the chartobjects on the sheet - in other
words, the code would go like this:
Set XLChart = Sheets("ChartSheetName")
Then everything else should work, if my guess is correct.
 

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

Similar Threads


Back
Top