Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Variables

Status
Not open for further replies.

GovNewbi

Technical User
Jul 14, 2010
83
CA
Is it possible to set a string variable equal to the value in several cells?

I want this to work...
Q1Titles = Range("Q1Titles").Value
Q2Titles = Range("Q2Titles").Value
Q3Titles = Range("Q3Titles").Value
Q4Titles = Range("Q4Titles").Value
Where Q1Titles is a range of 3 cells saying Jan, Feb, Mar. Q2Titles is a range of 6 cells saying Jan, Feb, Mar, Apr, May, Jun. So on and so forth.

I am using these variables to set the titles for the xaxis in a chart like so...
ActiveChart.SeriesCollection(1).XValues = Q1Titles

I have tried simply setting the xvalues equal to the range I want but this does not work because the workbook with these ranges is not active while the chart is being built.
 



hi,
Is it possible to set a string variable equal to the value in several cells?
Yes, but not the way you envision.

If A1 contains the value "Skip" and B1 contains the value "Vought" and MyName is declared as String then
Code:
dim MyName as String, r as range

for each r in range("A1:B1")
  MyName = MyName & r.Value
next
msgbox MyName
MyName would contain "SkipVought".

But this would not...
Code:
dim MyName as String

MyName = range("A1:B1").Value

msgbox MyName

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


BTW, you do not 'Set' variables.

You Set Objects.

You assign values to varaibles.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I see what you are saying but I am still not sure this will do what I want it to. I Don't want there to only be one label on the xaxis saying JanFebMar when I put in Q1Titles. I would want 3 labels Jan, Feb, and Mar. Would this do that?
 


Code:
Dim Q1Titles as range
Dim Q2Titles as range

Set Q1Titles = Range("A1:A3")
Set Q2Titles = Range("A1:A6")

ActiveChart.SeriesCollection(1).XValues = Q1Titles
Why would you have value axis assigne to TITLES? Seems like category data to me?????



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I might be just messing up wording again... I really have only been coding for like 2 months so the technicalities in the language is all still forein to me. I will try working with the code you posted and see if I can get it to do what I want... if not I will attempt to clarify my situation and repost. in the mean time I actually have another question about setting variables to... (unrelated to the first question)

If I have this...
Range("A" & i : "T" & i ).PasteSpecial , xlPasteSpecialOperationDivide
Why am I getting an error saying "Expected list seporator or )"

By the way i is a variable dimentioned as an integer representing a row number. It is initially ASSIGNED a value of 155 and increments by 1 each time a loop with this code is ran.
 
Range("A" & i & ":T" & i ).

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

Code:
Range("A" & i [b]":[/b]T" & i ).PasteSpecial , xlPasteSpecialOperationDivide
I prefer, as much cleaner, {where Cells(row, column)}
Code:
Range(Cells(i, "A"), Cells(i, "T")).PasteSpecial , xlPasteSpecialOperationDivide


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


oops...
Code:
Range("A" & i & ":T" & i ).PasteSpecial , xlPasteSpecialOperationDivide


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top