Programmatically using Range to update chart

R

royend

Hi.
I am trying to control my graph programmatically and it seems I need
to use a Range somehow. My code so far:
-----
Sub UpdateReport()
Dim query As String
Dim WS As Worksheet

Set WS = Worksheets("Oppsummering - kroner")

End = 2 * [B2]
Period = 2 * [B3]

For i = End - Period To End
If (i = End - Period) Then 'first cell added to range
query = WS.Cells(12, i).Value
Else
query = query & "," & WS.Cells(12, i).Value
End If
Next i

ActiveSheet.ChartObjects("Diagram 3").Activate
ActiveChart.SeriesCollection(1).XValues = _
Range(query)
ActiveChart.SeriesCollection(1).Values = _
Range(query)
End Sub
-----

Why doesn't it work?
The range consist of values seperated by ",".
e.g: "120, 100, 80, 100"

Looking forward to your help...
 
J

JLGWhiz

I am not sure what WS.Cells(12, i).Value equates to, nor what the variable
query equates to, but I do know the if you use Range(anyVariable) then
anyVariable has to equate to a range address, e.g. "A1:B4" or something
similar. If you are trying to use it with the variable "query" equating to
an integer or set of integers, it won't work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top