VBA. I’m trying to edit a chart by adding multiple new series to indicate when certain phases begin at certain times. I’ve done this by writing code that creates series using x values of the date i.e. (10/1/24 to 10/1/24) and y values -1000 to 1000 to create a vertical line. However I was wondering if there was a way to exclude these new series from the legend, as the legend gets too large, and the plot is running slowly – causing difficulties with manually deleting legend entries.
I’m very new to VBA and coding in general – any tips or suggestions are welcome. Thank you!!
Sub Plottest()
With ActiveChart.Axes(xlCategory)
.MinimumScale = 45566
.MajorUnit = 30.5
.MaximumScale = 45748
End With
With ActiveChart.SeriesCollection.NewSeries
.Name = "='Connection Data'!B2"
.XValues = "='Connection Data'!A2:A3"
.Values = "='Connection Data'!C2:C3"
.Format.Line.ForeColor.RGB = RGB(0, 0, 0)
End With
With ActiveChart.SeriesCollection.NewSeries
.Name = "='Connection Data'!B4"
.XValues = "='Connection Data'!A4:A5"
.Values = "='Connection Data'!C4:C5"
.Format.Line.ForeColor.RGB = RGB(0, 0, 0)
End With
With ActiveChart.SeriesCollection.NewSeries
.Name = "='Connection Data'!B6"
.XValues = "='Connection Data'!A6:A7"
.Values = "='Connection Data'!C6:C7"
.Format.Line.ForeColor.RGB = RGB(0, 0, 0)
End With
With ActiveChart.SeriesCollection.NewSeries
.Name = "='Connection Data'!B8"
.XValues = "='Connection Data'!A8:A9"
.Values = "='Connection Data'!C8:C9"
.Format.Line.ForeColor.RGB = RGB(0, 0, 0)
End With
End Sub
Miles Baker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1