Create dynamic variable names?

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.
 
R

Rob Bovey

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 *
 
T

Tim Williams

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.
 
J

J Kruger

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.
 
T

Tim Williams

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.
 

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

Top