ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping (https://www.excelbanter.com/excel-programming/319621-looping.html)

Hannes

Looping
 
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....

K Dales[_2_]

Looping
 
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


"Hannes" wrote:

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....


Hannes

Looping
 
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.

"K Dales" wrote:

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


"Hannes" wrote:

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....


K Dales[_2_]

Looping
 
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.

"Hannes" wrote:

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.

"K Dales" wrote:

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


"Hannes" wrote:

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....



All times are GMT +1. The time now is 05:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com