variable code

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

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
 
Paul said:
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
 
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
 

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

Back
Top