refer variable name by value from string

zico8

Board Regular
Joined
Jul 13, 2015
Messages
227
Hi,

I have some defined variables where have added some values:

temp_1 = "red"
temp_2 = "black"
temp_3 = "blue"
etc.

how can I refer to the correct one by text string?

msgbox = "temp_" & selection.row
 
Last edited:
but if my table headers are not "1", "2", "3" but "tom", "jack", "dave" and values stored in variables named "temp_tom", "temp_jack", "temp_dave" ??
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
It doesn’t matter what they are since you’re looping using an index number.
 
Upvote 0
Your code does not refer to the columns by name, so it doesn’t matter what they’re called.
 
Upvote 0
By iteration I get all columns headers and then I need to be sure that value from correct variable is taken.
It does not matter wheter user replaced table columns because macro will iterate by all of them, get its name and (by merging with "temp_") will take the correct value.
 
Upvote 0
Then I suggest you use a collection or dictionary, not separate variables.
 
Upvote 0

Forum statistics

Threads
1,217,257
Messages
6,135,502
Members
449,944
Latest member
parag385

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