MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Assign a value to a number of Variables


Posted by Sam S on February 13, 2002 7:50 PM

I can't seem to work this one out, I have several Constants that have been assigned specific values. In my procedure I need to often assign a number of variables (changes during the procedure) to one of these constants. Is there a one liner that will do this e.g.

var1, var4, var5, var7 = constant2

Thanks in anticipation.


Posted by DRJ on February 13, 2002 8:15 PM

Hi

If they are in an array then you can i.e.

Dim MyVar(9) as Integer 'Arrays start at 0 by default so this array has 10 spots

Then

For x = 1 to 10
MyVar(x-1) = NewValue
Next x


HTH

DRJ

Posted by Sam S on February 13, 2002 8:32 PM

Not array - have several Constants declared in VBA - or am I misunderstanding response

Posted by DRJ on February 14, 2002 9:44 AM

Re: Not array - have several Constants declared in VBA - or am I misunderstanding response

Just Declare the variables as an array and then this will work.

DRJ

: Hi : If they are in an array then you can i.e. : Dim MyVar(9) as Integer 'Arrays start at 0 by default so this array has 10 spots : Then : For x = 1 to 10 : MyVar(x-1) = NewValue : Next x : : HTH : DRJ :

Posted by Sam S on February 14, 2002 1:13 PM

Thanks - works a treat - brain was not in gear

DRJ :