Dynamic update of chart-series using a dynamic range

Issue

I am in need for some coding assistance, as I’m fairly new to coding and do not understand what I am doing (writing) wrong. This is the first time I am trying to update charts using vba and would like to get it right.
thank you for any help 🙂

I have a timeseries that I update ad-hoc. I wish to update the chart using vba, but when i get to the chartobjects it errors. so, what am I doing wrong?

this is what I am trying to do (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 msg I get is: "Run-time error 438: Object doesn’t support this property or method"

cheers 🙂

Solution

Two issues:

.ChartObjects("chSpreader").Chart.SeriesCollection...
  • Rather than assign the Range, assign its .Address, including the sheet name:
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

Answered By – BigBen

Answer Checked By – Candace Johnson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.