ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   variable code (https://www.excelbanter.com/excel-programming/326845-variable-code.html)

Paul

variable code
 
Would appreciate help with what I am doing wrong.. vba
does not like the lines containing the variables for
setting chart parameters:

Sub last1500()

Dim currentrow As Integer
Dim beginrow As Integer

currentrow = Worksheets("data").Range("aa1").Value
beginrow = currentrow - 1500

Application.ScreenUpdating = False

ActiveSheet.ChartObjects("Chart 10").Activate
ActiveChart.SeriesCollection(1).Values = "=DATA!
RbeginrowC5:RcurrentrowC5"
ActiveChart.SeriesCollection(2).Values = "=DATA!
RbeginrowC19:RcurrentrowC19"

End Sub


Fredrik Wahlgren

variable code
 

"Paul" wrote in message
...
Would appreciate help with what I am doing wrong.. vba
does not like the lines containing the variables for
setting chart parameters:

Sub last1500()

Dim currentrow As Integer
Dim beginrow As Integer

currentrow = Worksheets("data").Range("aa1").Value
beginrow = currentrow - 1500

Application.ScreenUpdating = False

ActiveSheet.ChartObjects("Chart 10").Activate
ActiveChart.SeriesCollection(1).Values = "=DATA!
RbeginrowC5:RcurrentrowC5"
ActiveChart.SeriesCollection(2).Values = "=DATA!
RbeginrowC19:RcurrentrowC19"

End Sub


Instead of "=DATA!RbeginrowC5:RcurrentrowC5"
try something like this
Evaluate("DATA!R" + Trim(Cstr(beginrow)) & "C5:R" & Trim(Cstr(currentrow)) &
"C5")

/Fredrik



Jim Thomlinson[_3_]

variable code
 
Your varibales are snot variables if thery are part of a string. You need to
pull them out of the string something like this...

ActiveChart.SeriesCollection(1).Values = "=DATA!
R" & beginrow & "C5:R" & currentrow & "C5"
ActiveChart.SeriesCollection(2).Values = "=DATA!
R" & beginrow & "C19:R" & currentrow & "C19"

HTH
"Paul" wrote:

Would appreciate help with what I am doing wrong.. vba
does not like the lines containing the variables for
setting chart parameters:

Sub last1500()

Dim currentrow As Integer
Dim beginrow As Integer

currentrow = Worksheets("data").Range("aa1").Value
beginrow = currentrow - 1500

Application.ScreenUpdating = False

ActiveSheet.ChartObjects("Chart 10").Activate
ActiveChart.SeriesCollection(1).Values = "=DATA!
RbeginrowC5:RcurrentrowC5"
ActiveChart.SeriesCollection(2).Values = "=DATA!
RbeginrowC19:RcurrentrowC19"

End Sub




All times are GMT +1. The time now is 01:47 PM.

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