Create dynamic variable names?

  • Thread starter Thread starter J Kruger
  • Start date Start date
J

J Kruger

Hi,

I have been looking everywhere on how to create dynamic variables in excel.
I want the same result as what the eval() function in JavaScript gives. ie.

a1 = new Array(10);
a1[0] = "hello";
alert(eval("a" + 1)[0]);

or

for(i = 0; i <=10; i++){
eval("a"+i) = i;}

Any help would be appreciated.
 
There's no way to do this is VB/VBA. It's just not a supported feature.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *
 
If you want to reference items/values via "names" created at runtime then
try using a Dictionary object.
Creating variable names at run-time (even when it's possible) is usually not
the best approach to a problem.

Tim.
 
Thanks.

The dictionary option unfortunately can only one value/reference per
key.
So you are stuck again with creating an array or variable for each key
to contain more than one value.
Then you must in any case again make dynamic arrays/variables.

I will keep suffering with VB until it becomes a REAL language.
 
If you were to describe what you're trying to do I'm sure you will get at
least one viable suggestion which does not involve creating dynamic
variables. Even in languages where this is possible (eg.
javascript/vbscript) there are few occasions where it's really warranted.

Tim.
 
Back
Top