Hello Excelers:
I've been automating some charting with arrays. This bit allows me to create trend charts for X number of series. For some reason this sometimes creates an extra legend entry that contains no data. Has anyone else experience this? or do you see an err in my code? Suggestions welcome.
Thanks,
Sub Charting_TopX()
Dim Brow, SeriesNumber As String
SeriesNumber = Sheets("Charting").Range("A1").Value
With ActiveWorkbook.Charts.Add
End With
For x = 1 To SeriesNumber
Brow = 20 + x
With ActiveChart
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(x).Name = "=Charting!R" & Brow & "C2"
ActiveChart.SeriesCollection(x).Values = "=Charting!R" & Brow & "C3:R" & Brow & "C28"
ActiveChart.SeriesCollection(x).XValues = "=Charting!R19C3:R19C28"
End With
Next x
ActiveChart.ChartType = xlLine
With ActiveChart
.Location Where:=xlLocationAsObject, Name:="Charting"
End With
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlRight
ActiveChart.HasDataTable = False
With ActiveChart
.Parent.Name = "MyChart"
.HasTitle = False
End With
End Sub
I've been automating some charting with arrays. This bit allows me to create trend charts for X number of series. For some reason this sometimes creates an extra legend entry that contains no data. Has anyone else experience this? or do you see an err in my code? Suggestions welcome.
Thanks,
Sub Charting_TopX()
Dim Brow, SeriesNumber As String
SeriesNumber = Sheets("Charting").Range("A1").Value
With ActiveWorkbook.Charts.Add
End With
For x = 1 To SeriesNumber
Brow = 20 + x
With ActiveChart
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(x).Name = "=Charting!R" & Brow & "C2"
ActiveChart.SeriesCollection(x).Values = "=Charting!R" & Brow & "C3:R" & Brow & "C28"
ActiveChart.SeriesCollection(x).XValues = "=Charting!R19C3:R19C28"
End With
Next x
ActiveChart.ChartType = xlLine
With ActiveChart
.Location Where:=xlLocationAsObject, Name:="Charting"
End With
With ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlRight
ActiveChart.HasDataTable = False
With ActiveChart
.Parent.Name = "MyChart"
.HasTitle = False
End With
End Sub