Avatar of Fordraiders
Fordraiders
Flag for United States of America asked on

create a combobox at runtime and fill with data on a multipage userform Page tab

vba excel 2010

What I have:
Userform =  userform1
Multipage control =  Pages 1 to 9

I found this code:

But this code does not place the combobox on a userform and specifically "Page9"  ?





Sub CreateComboBox1()
    With ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", _
                Link:=False, DisplayAsIcon:=False, Left:=50, Top:=80, Width:=100, _
                Height:=15)
        With .Object
            .AddItem "Date"
            .AddItem "Player"
            .AddItem "Team"
            .AddItem "Goals"
            .AddItem "Number"
        End With
    End With
End Sub


Thanks
fordraiders
Microsoft Excel

Avatar of undefined
Last Comment
Fordraiders

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Norie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Fordraiders

ASKER
Thanks, The reason i was trying to find code using the
            .AddItem "Date"
            .AddItem "Player"
            .AddItem "Team"
            .AddItem "Goals"
            .AddItem "Number"

Is because I may have sometimes 50 items or more to add to the combobox ?

or maybe if i have to use another line, (using your code) how to multiline it.(to extend the array list to another line would be fine) ?


Also
imnorie, just a question...I noticed browsing through code that most show code using  Initialize event.  This can be done regardlesss from a command button or some event from another combobox ?

Thanks very much fordraiders
Norie

You can change the code I posted to use AddItem.
With cbo
       .AddItem "Date"
       .AddItem "Player"
       .AddItem "Team"
       .AddItem "Goals"
       .AddItem "Number"
End With

Open in new window

By the way, where will the 50 (or whatever) items be coming from?

You could call the code from a command button click or some other event, I posted for the Initialize event because your title mentioned adding at runtime.
Fordraiders

ASKER
By the way, where will the 50 (or whatever) items be coming from?
hard coding it...
Your help has saved me hundreds of hours of internet surfing.
fblack61
Norie

Oh, thought they might have been stored somewhere, eg a worksheet.

That would have made it a lot easier to populate the combobox and would avoid hard-coding.
Fordraiders

ASKER
thanks very much