Hi Everyone.
I'm trying to make a chart with 3 series, that I can add or take out using toggle buttons. The series are called AAA, BBB, and CCC. I want to be able to make sure that they always show up in the same order, that is so that AAA would always be first when it is turned on, BBB would always be second, or first if AAA is turned off, and CCC would always be third, unless BBB is turned off, in which case it would be second, or first, if AAA and BBB are both off.
The code I have to do this so far is as follows:
Private Sub btnToggleAAA_Click()
If btnToggleAAA.Value = True Then
With Worksheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection.NewSeries
.Values = Range(Cells(2, 1), Cells(4, 1)).Value
.Name = Cells(1, 1).Value
.PlotOrder = 1
End With
Else
Worksheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection("AAA").Delete
End If
End Sub
Private Sub btnToggleBBB_Click()
If btnToggleBBB.Value = True Then
With Worksheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection.NewSeries
.Values = Range(Cells(2, 2), Cells(4, 2)).Value
.Name = Cells(1, 2).Value
On Error GoTo ErrorHandler ' This is in case there is no first series
.PlotOrder = 2
End With
Else
Worksheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection("BBB").Delete
End If
ErrorHandler:
End Sub
Private Sub btnToggleCCC_Click()
If btnToggleCCC.Value = True Then
With Worksheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection.NewSeries
.Values = Range(Cells(2, 3), Cells(4, 3)).Value
.Name = Cells(1, 3).Value
On Error GoTo ErrorHandler ' this is in case there is no second series.
.PlotOrder = 3
End With
Else
Worksheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection("CCC").Delete
End If
ErrorHandler:
End Sub
Would anyone be able to help out with this? I want to be able to take the series out of the chart, and put it back in, not just hide it but keep it in the chart.
Thanks!
ChartPlot.xlsm
Bookmarks