PDA

View Full Version : Sleeper: If statements and Chart Series



goldie12
07-22-2005, 06:37 AM
I am trying to write and if statement for a chart series collection. I have two columns of data on a Sheet called "Data". I am adding two series if both columns have data, if only one does then I am only needing to add one series, vice versa. The two columns of data are called "Stuff" and "Junk". So if I only have data under one of the columns then just add one series, if I have data under both columns then add two series. Any suggestions. The columns that the data are in is A2 and F2.

Here is the code that I have now:


Sheets("Data").Select
While ActiveSheet = True
If IsEmpty(Range("F2")) Then
Charts.Add
ActiveChart.ChartType = xlXYScatter
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Data!R2C1:R65536C1"
ActiveChart.SeriesCollection(1).Values = "=Data!R2C4:R65536C4"
ActiveChart.SeriesCollection(1).Name = "=""Stuff"""
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "test"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Amount"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
"Time"
End With
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(2).Delete
Else
Charts.Add
ActiveChart.ChartType = xlXYScatter
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Data!R2C1:R65536C1"
ActiveChart.SeriesCollection(1).Values = "=Data!R2C4:R65536C4"
ActiveChart.SeriesCollection(1).Name = "=""Stuff"""
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).XValues = "=Data!R2C6:R65536C6"
ActiveChart.SeriesCollection(2).Values = "=Data!R2C9:R65536C9"
ActiveChart.SeriesCollection(2).Name = "=""Junk"""
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "test"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Amount"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
"Time"
End With
End If
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(3).Delete

Justinlabenne
07-22-2005, 04:56 PM
This may help, it works in a way that you describe.

Just add / Remove data