Defining a Variable Whose Name Is Composed of Multiple Strings

Kelinky_Sama

New Member
Joined
Aug 27, 2016
Messages
6
I'm not entirely sure if that name is the most understandable. Oh, well.

This falls in the same general vein as the last question I asked (which has been answered, and I am quite thankful for that), but plays out in reverse. I'll use a similar example situation for consistency.

Now, say that I have a UserForm which contains the string variable "Nickname", which has been given the value "Melvin". In a separate module, I have another string variable, "Catalogue.Names". Within the UserForm, the value for Label1.Caption is "Catalogue". I would like to use this value, in conjunction with the text ".Names", to let the value for "Catalogue.Names" be equal to that of "Nickname". Consider the following:

HTML:
Dim Nickname As String
Nickname = "Melvin"
Me.Label1.Caption & ".Names" = Nickname

As can be expected, this only results in a syntax error.

Is there any way to work around this? Using the label's caption is rather important, since its value would change depending on circumstance. I would really appreciate the help.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You seem to be looking for a VBA counterpart of the INDIRECT. I am not sure such a functionality exists.

A workaround would include:
- Defining a user type (say, MyType) with element Names As String;
- Declaring an array: say, Dim MyArray(1 to 10) As MyType;
- Turning your Catalogue into say, MyArray(1);
- Dynamically converting your Label1.Caption "Catalogue" into 1 using an If or a Select Case;
- Only then MyArray(1).Names = Nickname.
 
Upvote 0
I see. I wasn't aware of the existence of user types (which should probably give some insight into how new I am to this), but they certainly do make things easier!

Thank you for your help!
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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