VBA Eval Dynamic Variables

jaybee3

Active Member
Joined
Jun 28, 2010
Messages
307
So I've previously used Bash to do this. I was wondering if it's possible in VBA.

I have a variable (let's call it ii) that will change based on a function...etc
I then have another set of variables let's call then a1, a2, a3.

Is it possible to do something like evaulate(a & "ii")? to get the value held in a1, a2, a3..etc based on ii.?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
a1="Bob", a2="harry", a3="June"

are they really an array of names

if so rather than
dim a1 as string
dim a2 as string
dim a3 as string

we would
dim a() as string

redim a(3) to size it to our needs

a(1)="bob"

a(2)="harry"

a(3)="June"


so if ii is an index say =2

a(ii) ="harry"
so your set of varibles could be a VBA array ()

But if you are asking "can you programatically build the name of a Variable" to get the content of that variable

I think NO not in VBA ... But I could be wrong!
 
Last edited:
Upvote 0
Hi

No.

The closest to what you want is:

- an array, and then you can use a(1), a(2), etc.

- a collection or a dictionary object. In that case you can use a1, a2, etc. as key

An array is the simplest solution.
 
Upvote 0
OK cheers for the quick responses and suggestions guys. I'll try an array of arrays or collection.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top