ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Programmatically using Range to update chart (https://www.excelbanter.com/excel-programming/396754-programmatically-using-range-update-chart.html)

royend

Programmatically using Range to update chart
 
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...


JLGWhiz

Programmatically using Range to update chart
 
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.

"royend" wrote:

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...




All times are GMT +1. The time now is 07:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com