Dynamic Reference a collection

Puertorekinsam2

New Member
Joined
May 16, 2018
Messages
2
I have six collections of auto generated user form controls

Code:
Dim MainLabels As Collection
Dim Metric1 As Collection
Dim Metric2 As Collection
Dim Metric3 As Collection
Dim Metric4 As Collection
Dim Metric5 As Collection

And I know I can add a control with this type of code:

Code:
MainLabels.Add ctrl, ctrl.Name

But what I would like to do use a variable to indicate which collection I am adding to:
Code:
Collection.name(Metric & i ).Add ctrl, ctrl.Name
I just can't find anything on line that tells me how to do this.

I know I could do this with just the naming of the controls:
Code:
Set ctrl = Me.Controls.Add("Forms.Label.1", "Metric_& i & "_barline" )

but later on this will be less elegant than I had originally hoped.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Why not just create a collection of collections?


I was at lunch and saw this response... I was going to come back and say I don't think you understood what I wanted to do. Luckily, on the way back I realized exactly what you meant. Not what I was thinking, but very clever :).


Thank you!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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