ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Assigning a Range to (https://www.excelbanter.com/excel-programming/289661-assigning-range.html)

Alex A

Assigning a Range to
 
Why won't excel let me assign the X and Y values for my
graph dynamically???? It is this line that is erroring
out:
XValues = "=Query!R" & CStr(x1) & "C1:R" & CStr(x2) & "C1"


Related Code:
x1 = IVSLH2Range.Row + 1 'Dynamic Row Assignment -
Starting Row Number
x2 = IVSLH2Range.Row + intRowCountIVSLH2 - 1 'Dynamic
Row Assignment - Ending Row Number

XValues = "=Query!R" & CStr(x1) & "C1:R" & CStr(x2) & "C1"
YValues = "=Query!R" & CStr(x1) & "C5:R" & CStr(x2) & "C5"

'Update Graph
Sheets("Chart2").Select
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).XValues = XValues
ActiveChart.SeriesCollection(1).Values = YValues


Alex A

Assigning a Range MORE INFO
 
I really need to solve this so here is the code!
The error I get says, "Run-Time Error '1004':
Unable to Set the XValues Property of the Series Class.

Compiler takes me to this line...
XValues = "=Query!R" & CStr(x1) & "C1:R" & CStr(x2) & "C1"

Which is related to this line...
ActiveChart.SeriesCollection(1).XValues = XValues


HERE IS THE WHOLE RELEVANT BLOCK:
x1 = IVSLH2Range.Row + 1

If IVSLH2Range.Offset(intRowCountIVSLH2 - 1, 2).Value
< Year(Date) Then
x2 = IVSLH2Range.Row + intRowCountIVSLH2 - 1
Else
x2 = IVSLH2Range.Row + intRowCountIVSLH2 - 2
End If

'Update Graph Variables
intRowCountIVSLH2 2 Then
XValues = "=Query!R" & CStr(x1) & "C1:R" & CStr(x2) & "C1"
YValues = "=Query!R" & CStr(x1) & "C5:R" & CStr(x2) & "C5"

'Update Graph2
Sheets("Chart2").Select
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).XValues = XValues
ActiveChart.SeriesCollection(1).Values = YValues
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = strCompanyName
End With
ActiveChart.ChartArea.Select


Alex A

MORE INFO REVISED
 
Sorry I got that backwards:

Compiler takes me to this line...
ActiveChart.SeriesCollection(1).XValues = XValues

Which is related to this line...
XValues = "=Query!R" & CStr(x1) & "C1:R" & CStr(x2) & "C1"

HELP!


All times are GMT +1. The time now is 12:05 PM.

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