Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Check for Data series

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 Whe=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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Check for Data series

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
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Ben H" wrote in message
...
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 Whe=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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to format a worksheet to tab through a series of check boxes? charvel Excel Worksheet Functions 0 April 21st 08 03:53 PM
How do I delete an already created series of check boxes? Tony Excel Discussion (Misc queries) 2 July 5th 07 09:52 PM
hiding data series with check/uncheck boxes BigSmile Mannequins Inc. Charts and Charting in Excel 1 November 11th 06 10:24 AM
Series of check boxes Steph[_6_] Excel Programming 1 August 29th 05 11:47 PM
VBA to check if there is a data series in a chart? Jon Peltier[_7_] Excel Programming 1 July 6th 04 08:45 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"