Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create dynamic variable names?
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create dynamic variable names?
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 * "J Kruger" wrote in message m... 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. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create dynamic variable names?
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 Kruger" wrote in message m... 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. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create dynamic variable names?
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. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Create dynamic variable names?
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. "J Kruger" wrote in message om... 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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Need to replace one dynamic variable with another dynamic variable | Excel Worksheet Functions | |||
Dynamic Worksheet Names | Excel Discussion (Misc queries) | |||
Dynamic scenarios - more than 2 variable using data tables in Exc | Excel Discussion (Misc queries) | |||
dynamic summed range based on a variable | Excel Worksheet Functions | |||
Dynamic Worksheet Names | Excel Worksheet Functions |