excelvbarangeexcel-charts

Dynamic update of chart-series using a dynamic range


I am trying to update charts using VBA.

I have a timeseries that I update ad-hoc. I wish to update the chart using VBA. When I get to the chartobjects it errors.

Both the chart and the series have names:

Dim tsEURLengde As Integer
Dim rngEUR As Range

tsEURLengde = Range("A2").Value 'A2 is count of rows containing chartdata

Set rngEUR = cnGrafer.Range("B5", cnGrafer.Range("b5").Offset(tsEURLengde)) 'cnGrafer is the ws codename
cnGrafer.ChartObjects("chSpreader").SeriesCollection("Bank 2 5y").Values = cnGrafer.Range("B5", cnGrafer.Range("b5").Offset(tsEURLengde))

The error message is:

"Run-time error 438: Object doesn't support this property or method"


Solution

  • Two issues:

    .ChartObjects("chSpreader").Chart.SeriesCollection...
    
    With cnGrafer
       Dim s As String
       s = "'" & .Name & "'!" & .Range("B5",.Range("b5").Offset(tsEURLengde)).Address
    
       .ChartObjects("chSpreader").Chart.SeriesCollection("Bank 2 5y").Values = s
    End With