vba to prevent display of default series in doughnut chart

D

diegoo

I am generating a doughnut chart using VBA and am having two immediat
issues:

1) I am using the following line to ensure that the default chart tha
is generated when I invoke the Charts.Add method is a doughnut chart:

Application.SetDefaultChart FormatName:=xlDoughnut

Is there a more elegant approach to ensuring that any chart create
ends up being a doughnut chart, maybe when invoking the Charts.Ad
method? I have tried to specify ChartType = xlDoughnut after th
Charts.Add method but this does not do the trick every time (see cod
snippet below).

2) When the doughnut chart is added (immediately after the execution o
the Chart.Add line), Excel automatically displays a series (calle
Series1) that I do not need or want. Actually I would like to ensur
that the chart is clear of any objects before I plot my own firs
series on it. I am using the following code:

Charts.Add
With ActiveChart
.ChartType = xlDoughnut
.SeriesCollection.NewSeries.Name = "PrimerData"
.SeriesCollection(1).Values = Array(Value1, Value2, Value3, _
Value4)
.Location Where:=xlLocationAsObject, Name:="Sheet2"
End With

PS I would feel honored to hear from Jon, Tushar or Mala... I am reall
digging into charting deep and your names are gold
 
J

Jon Peltier

You could run a simple loop to clean out the chart before you add your
own series:

Do while activechart.seriescollection.count>0
activechart.seriescollection(1).delete
Loop

While donut charts are useful in many cases, I don't think anyone in
their right mind wants their default chart to be a donut chart.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
D

diegoo

Hi Jon,

Thank you for your input. Three lines... hum: you make it sound s
easy!

CIAO ;-
 

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