Remove/delete series from chart

H

Henk

Based on certain values in my worksheet, I want to remove some lines from a
chart. Recording a macro removing series 1 from the chart results in :

ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection(1).Delete

Running this macro results in :

Run-time error '1004'
Delete method of Series class failed

Question is "How do I remove series from a chart in VB" ?

Regards,

Henk
 
B

Bernard Liengme

I recorded this macro

Sub Macro1()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(2).Select
Selection.Delete
End Sub

and it works when I run it.

So does

Sub Macro2()
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(2).Delete
End Sub

best wishes
 
D

Don Guillett

ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).Delete
 
H

Henk

Bernard,

tHenks for your prompt reply.

I tried your first code and ................ error.

Tried it agian with SeriesCollection(2), (instead of 1), and
................. it worked!

Tried it agian with SeriesCollection(3) and ................... error

Tried it agian with SeriesCollection(4) and ................... error

Tried it agian with SeriesCollection(1) and ................... error

Anyone any idea ????

Regards,

Henk
 
J

Jon Peltier

If it is a line or XY chart, and the series data range does not contain
plottable data (which is why you're probably trying to delete the series),
then a lot of actions cannot be done directly on the series. However, you
can change the chart type of the series, then delete it:

ActiveChart.SeriesCollection(1).ChartType = xlColumnClustered
ActiveChart.SeriesCollection(1).Delete

- Jon
 
H

Henk

Jon,

You're right. I could not delete them because there aint no data (not the
reason why I want to delete them).

I will try you're suggestion changing the type of graph, delete the
necessary lines, and change th type back again.

Many thanks.

Regards,

Henk
 
J

Jon Peltier

Don't change the whole chart, which is likely to spoil formatting and so
forth. Just change the individual series, and you won't need to change the
type back, because the series will be gone.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services, Inc.
http://PeltierTech.com/WordPress/
_______

..
 

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