Referencing the content of a variable as a variable irself

patupatu

New Member
Joined
Apr 7, 2011
Messages
23
Hello. In have a list of variables named Button1 Button2 Button3
In a For loop, can I reference the buttons asÑ
VarButton="Button"
For I = 1 to 3
Button = VarButton & I ´ Button value would be "Button1" an so on
Next I

Thank you
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Not sure exactly what you are wanting to do, but you could access all The objects on your userform whose names start with Button like this:

Code:
VarButton = "Button"
For Each tObj In UserForm1.Controls
    If Left(tObj.Name, 6) = "Button" Then
        tObj.Caption = VarButton
    End If
Next
 
Upvote 0
Actually, I have a series of buttons all names SNx where x goes from 1 to 13, ie SN1, SN2, SN3. Eventually have to change the caption on each button depending on the value of a variable (x from one to 13) Instead of using a Select Case premitive, one case for each posible value of x, I might be able to use a variable Button = "SN" and concatenate with x thus producing SN1, SN2, SN3 and so on.

Something like this

For x=1 to 13
With Button & x ' meaning SN1, SN2, SN3, .....
set ot instructions
next x

Not sure exactly what you are wanting to do, but you could access all The objects on your userform whose names start with Button like this:

Code:
VarButton = "Button"
For Each tObj In UserForm1.Controls
    If Left(tObj.Name, 6) = "Button" Then
        tObj.Caption = VarButton
    End If
Next
 
Upvote 0
By the way, thank you for your time.:)


Not sure exactly what you are wanting to do, but you could access all The objects on your userform whose names start with Button like this:

Code:
VarButton = "Button"
For Each tObj In UserForm1.Controls
    If Left(tObj.Name, 6) = "Button" Then
        tObj.Caption = VarButton
    End If
Next
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

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