Check for Data series

G

Guest

Hi all. I have a macro that on the first run through, it will add 2 data
series to the chart it creates. On the second run through, it only adds one.
Is there a way to check if there are 2 data series? The end goal is to
delete the second and unused data series. Here is the function that I use.

Function PlotSigma(strDataName, strChartName, strChartTitle)

With Sheets(strDataName)
Set rng1 = .Range(.Cells(2, 4), _
.Cells(2, 4).End(xlDown))
Set rng2 = .Range(.Cells(2, 3), _
.Cells(2, 3).End(xlDown))
End With

Charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.Location Where:=xlLocationAsNewSheet, Name:=strChartName
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = Sheets(strDataName).Cells(1, 4)
ActiveChart.SeriesCollection(1).XValues = rng1
ActiveChart.SeriesCollection(1).Values = rng2
end function

Thanks - Ben H.
 
J

Jon Peltier

This gets rid of all the series in the chart:

do while activechart.seriescollection.count > 0
activechart.seriescollection(1).delete
loop

Then continue by adding back the first series (your .NewSeries line). Or
loop while the series count >1, and you don't need to add the first series.

- 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

Similar Threads

I hate lunch 1
Adding Chart problem 0
Loop to create charts 1
Floating Chart? 1
Error Creating Chart 1
Help Please !!! 3
Error with Using Macro for XYScatter plots 2
add a chart in a Add-In 1

Top