Defining a Variable Using Multiple Parts that Represent Another Variable

Kelinky_Sama

New Member
Joined
Aug 27, 2016
Messages
6
So, this question is rather similar to the one I've asked before.

Let's say that I have a variable called "Nickname" within a UserForm that I would like to have the same value as that of another variable whose name can be built up from different captions in the UserForm. This other variable is identified by "Catalogue.Names(1)" (located in a different module) and has a value of "Melvin". Imagine that I have in the UserForm a label with a caption of "(1)" simply called "Label1". I would thus like to do something along the following:

HTML:
Dim Nickname As String

Catalogue.Names(1) = "Melvin"
Nickname = "Catalogue.Names" & Me.Label1.Caption

However, this would just make the value of Nickname "Catalogue.Names(1)". I tried using CStr() to see if it would help, but it just returns the same value as before.

Is there any way around this? I know I've made it sound as though I could just specify "Melvin" or the other variable directly, but the value of Label1 changes based on circumstance, and I'd like the code to be accustomed to that.

I am currently running on Windows 8.1 with Microsoft Excel 2016 32-bit.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Is this what you need?

Code:
Dim Nickname As String

Catalogue.Names(1) = "Melvin"
Nickname = Catalogue.Names(Replace(Replace(Me.Label1.Caption, "(", ""), ")", ""))
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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