K
Keith R
I have a graph with up to 6 series. I need to dynamically add and remove
series depending on how what data is present.I don't know how to do it well,
so I am deleting all but one existing series and adding back one series at a
time until I get the right number I need.
All my series are set to named ranges, but I'm having trouble with the VBA
syntax to add a named range as a new series. Below is some edited code I
have so far, originally based on a recorded macro; I don't think it is
copying the named range to add it as a new series. Optimally, I'd like to
add a new series and have it (in the data source) refer directly to the
named range, rather than the specific cells in that range, so I can change
the graph by changing the named range if needed.
Any help greatly appreciated,
keith
Sub resetseries()
On Error Resume Next
ActiveSheet.ChartObjects("Chart 22").Activate
ActiveChart.SeriesCollection(6).Select
Selection.Delete
ActiveChart.SeriesCollection(5).Select
Selection.Delete
ActiveChart.SeriesCollection(4).Select
Selection.Delete
ActiveChart.SeriesCollection(3).Select
Selection.Delete
TotalSeries = (Sheet1.Range("B8").Value)
If TotalSeries > 1 Then
For j = TotalSeries To 1 Step -1
AddEachSeries = Choose(j, Act1, Act2, Act3, Act4, Act5)
AddEachSeries.Copy
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection.Paste Rowcol:=xlColumns,
SeriesLabels:=False, _
CategoryLabels:=False, Replace:=False, NewSeries:=True
ActiveChart.SeriesCollection(SeriesNum).Select
Application.CutCopyMode = False
ActiveChart.SeriesCollection(SeriesNum).ChartType =
xlColumnClustered
Next
End If
End Sub
series depending on how what data is present.I don't know how to do it well,
so I am deleting all but one existing series and adding back one series at a
time until I get the right number I need.
All my series are set to named ranges, but I'm having trouble with the VBA
syntax to add a named range as a new series. Below is some edited code I
have so far, originally based on a recorded macro; I don't think it is
copying the named range to add it as a new series. Optimally, I'd like to
add a new series and have it (in the data source) refer directly to the
named range, rather than the specific cells in that range, so I can change
the graph by changing the named range if needed.
Any help greatly appreciated,
keith
Sub resetseries()
On Error Resume Next
ActiveSheet.ChartObjects("Chart 22").Activate
ActiveChart.SeriesCollection(6).Select
Selection.Delete
ActiveChart.SeriesCollection(5).Select
Selection.Delete
ActiveChart.SeriesCollection(4).Select
Selection.Delete
ActiveChart.SeriesCollection(3).Select
Selection.Delete
TotalSeries = (Sheet1.Range("B8").Value)
If TotalSeries > 1 Then
For j = TotalSeries To 1 Step -1
AddEachSeries = Choose(j, Act1, Act2, Act3, Act4, Act5)
AddEachSeries.Copy
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection.Paste Rowcol:=xlColumns,
SeriesLabels:=False, _
CategoryLabels:=False, Replace:=False, NewSeries:=True
ActiveChart.SeriesCollection(SeriesNum).Select
Application.CutCopyMode = False
ActiveChart.SeriesCollection(SeriesNum).ChartType =
xlColumnClustered
Next
End If
End Sub