Consulting

Results 1 to 2 of 2

Thread: Sleeper: If statements and Chart Series

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

    Sleeper: If statements and Chart Series

    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

  2. #2
    VBAX Mentor Justinlabenne's Avatar
    Joined
    Jul 2004
    Location
    Clyde, Ohio
    Posts
    408
    Location
    This may help, it works in a way that you describe.

    Just add / Remove data
    Justin Labenne

Posting Permissions

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