使用单元格值更改图表系列值

Change chart series values with cell values

我想使用单元格值,例如(Range(Cells(25, 3), Cells(25, iMonths)) 而不是 $C$25:$N$25 用于图表的系列值,因为我需要使用根据日期变化的变量。是否有这样做的方式?

    Dim dtToday As Date
    Dim dtStartDate As Date
    Dim iMonths As Integer
    dtToday = Date
    dtStartDate = "01/01/2021"
    iMonths = DateDiff("m", dtStartDate, dtToday)

    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.FullSeriesCollection(6).Name = "='Sheet 1'!$C:$N"

单向 -

Dim cht As Chart
Dim sr As Series
Dim splt() As String

    Set cht = ActiveSheet.ChartObjects("Chart 2").Chart
    Set sr = cht.SeriesCollection(6)
    splt = Split(sr.Formula, ",")
    splt(2) = "'" & ActiveSheet.Name & "'!" & Range(Cells(25, 3), Cells(25, iMonths)).Address
    sr.Formula = Join(splt, ",")