Consulting

Results 1 to 3 of 3

Thread: If statement for Scatter Chart

  1. #1
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location

    If statement for Scatter Chart

    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.

    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

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try this:

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

  3. #3
    VBAX Regular
    Joined
    Jul 2005
    Posts
    34
    Location
    Quote Originally Posted by DRJ
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •