Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

create a determined number of comboboxes at runtime on userform and fill each one seperately

vba excel 2013
Userform
Mutipage tab control --specifically tab9

The following code generates a combobox at runtime on a userform and specifically tab9

Private Sub UserForm_Initialize()
Dim cbo As MSForms.ComboBox

    Set cbo = Me.MultiPage1.Pages(8).Controls.Add("Forms.Combobox.1")
    cbo.Left = 10
    cbo.Top = 10
       
End Sub With cbo
       .AddItem "Date"
       .AddItem "Player"
       .AddItem "Team"
       .AddItem "Goals"
       .AddItem "Number"
End With



Now what i need:

01---I need to be able to create and call up to 3 comboboxes.

02--- The comboboxes need to be aligned next to each other.

03-- I may or may not call all three at any given time.


combobox1 would have items:

With cbo1
       .AddItem "1/2 INCH"
       .AddItem "3/4 INCH"
       .AddItem "1 INCH"
       .AddItem "1 1/2 INCH"
       .AddItem "2 INCH"
End With

----------------------------------------------
With cbo2
       .AddItem "ADAPTER"
       .AddItem "BRASS"
       .AddItem "GALVANIZED"
       .AddItem "STEEL"
       .AddItem "312 STEEL"
End With


With cbo3
       .AddItem "BOLT"
       .AddItem "HHCS"
       .AddItem "SHCS"
       .AddItem "SET SCREWS"
       .AddItem "LAG SCREW"
End With



Thanks
fordraiders
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Why are you creating them at runtime? Why not create them at design time and set the visible property to False until such time as you want them visible.
Avatar of Fordraiders

ASKER

Because sometimes i need certain comboboxes in certain positions..
in certain sequences.

But
i could just would like to have this as a backup plan.
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks rorya,
just a quick side:

avItems(3) = Array("ADAPTER", "BRASS", "GALVANIZED", "STEEL", "312 STEEL" )

with the folowinf array.
If i need to carry Items to fill to a next line syntax for that ?


??
avItems(3) = Array("ADAPTER", "BRASS", "GALVANIZED", "STEEL", "312 STEEL"  &  _
& "MAGNETIC", "GRAY STEEL")

Thanks
fordraiders
Thanks very much