Hi,

I have a macro that plots a bunch of graphs based on option box selections. All my graphing code is set up similar, but I'm having a problem with getting my macro to plot selected data and put in the series name.

What happens is as follows:

I two fuel types and two tests for each fuel type. I want to plot two graphs (one for each fuel type), each of which contains two series (for each of the tests conducted with that fuel type). The first graph does everything I want. But for the second graph, only one data series plots and the name of the series (labeled to the right) is "Series 1", not the name I referenced in my code. I think the problem has to do with my calls to "ActiveChart" but I as I'm new to VBA I don't know how to refer to a chart name when I try to add a new series to it.

Below is my code:

Formula: copy to clipboard
If CheckBox3.Value = True Then

Charts.Add

With ActiveChart
.Name = "Chart2"
.ChartType = xlXYScatterSmooth
'x axis label spacing
.Axes(xlCategory).TickMarkSpacing = 10
.Axes(xlCategory).TickLabelSpacing = 10
.HasTitle = True
.ChartTitle.Text = "T_SEV_IN - MT_SEV_BUR22 for 28% H2"
'axes titles
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "T_SEV_IN (C)"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "D_TSEVIN_MTBUR22 (C)"
.Location Where:=xlLocationAsObject, Name:="Plots"
End With

With ActiveChart.Parent
.Height = 325
.Width = 500
.Top = Range("C29").Top
.Left = Range("C5").Left
End With

Set SheetName3 = Worksheets("FB3")
lastdatapoint3 = SheetName3.Cells(Rows.Count, 2).End(xlUp).Row

With Charts("Chart2")
.SetSourceData Source:=SheetName3.Range("$WB$3:$WB" & lastdatapoint3)
.SeriesCollection(3).XValues = SheetName3.Range("$R$3:$R" & lastdatapoint3)
.SeriesCollection(3).Name = Worksheets("Index").Range("A4")
End With
End If

If CheckBox4.Value = True Then
Set SheetName4 = Worksheets("FB4")
lastdatapoint4 = SheetName4.Cells(Rows.Count, 2).End(xlUp).Row

With Charts("Chart2")
.SeriesCollection.NewSeries
.SeriesCollection(4).Name = Worksheets("Index").Range("A5")
.SeriesCollection(4).Values = SheetName4.Range("$WB$3:$WB" & lastdatapoint4)
.SeriesCollection(4).XValues = SheetName4.Range("$R$3:$R" & lastdatapoint4)
End With
End If


I know that my graph is in the if statement for the first checkbox. But, I always graph both of these checkboxes at the same time and I don't want the plot to show up unless the checkboxes are selected.

All suggestions are appreciated!