PDA

View Full Version : [SOLVED:] If statement for Scatter Chart



goldie12
09-11-2005, 12:42 PM
Hello I am trying to excute the following code for a scatter graph. It includes an If statement stating that if there are no values in a range then just graph the range that does contain values. I can't seem to get it to say that if Either of the Columns A2 range or Columns C2 range are empty then just plot the one that is not empty, I both are empty then just create the chart and just name the SeriesCollection.Name for both groups. Any help would be appreciated. :banghead:


Function Test()
Sheets("Sheet1").Activate
While ActiveSheet = True
If IsEmpty(Range("C2")) Then
Charts.Add
ActiveChart.ChartType = xlXYScatter
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R2C1:R65536C1"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R2C2:R65536C4"
ActiveChart.SeriesCollection(1).Name = "=""Cars"""
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "test"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Distance (Miles)"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
"Price"
End With
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(2).Delete
Else
Charts.Add
ActiveChart.ChartType = xlXYScatter
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R2C1:R65536C1"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R2C2:R65536C4"
ActiveChart.SeriesCollection(1).Name = "=""Cars"""
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).XValues = "=Sheet1!R2C3:R65536C6"
ActiveChart.SeriesCollection(2).Values = "=Sheet1!R2C4:R65536C9"
ActiveChart.SeriesCollection(2).Name = "=""Planes"""
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "test"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Distance (Miles)"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = _
"Price"
End With
End If
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(3).Delete
Wend
End Function

Jacob Hilderbrand
09-11-2005, 12:56 PM
Try this:


If Range("A2").Text = "" Or Range("C2").Text = "" Then
'Do Something
Else
'Do Something Else
End If

goldie12
09-12-2005, 10:43 AM
Try this:


If Range("A2").Text = "" Or Range("C2").Text = "" Then
'Do Something
Else
'Do Something Else
End If



Works fine now. This post is solved.:clap: