1

I would like to use SeriesCollection.Extend method to extend the range of a chart. Worksheet(1) has the values

Column A Column B
DATE
6/1/2023 1
6/2/2023 4
6/3/2023
6/4/2023

The first 3 rows/columns are charted as "Chart 1". I want to extend the chart to include row 4 using the SeriesCollection.Extend method.

The macro:

Sub ExtendTrial()

Charts("Chart 1").SeriesCollection.Extend _
Source:=Worksheets("Sheet1").Range("$A$5:$B$5")

End Sub

gives a "Subscript out of range" error. The macro does not seem to allow me to add the xlColumn parameter

Scott Craner
  • 148,073
  • 10
  • 49
  • 81
oldsilenus
  • 11
  • 2

1 Answers1

1

I needed to use ChartObject in Excel 2019 to remove your error message and specify optional argument values to get the correct plot rather than let Excel try, and fail, to determine.

Option Explicit

Sub ExtendTrial()

    Worksheets("Sheet1").ChartObjects("Chart 1").Chart.SeriesCollection.Extend _
        Source:=Worksheets("Sheet1").Range("$A$5:$B$5"), Rowcol:=xlColumns, CategoryLabels:=True
End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101