Fordraiders
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.C omboBox.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
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can change the code I posted to use AddItem.
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.
With cbo
.AddItem "Date"
.AddItem "Player"
.AddItem "Team"
.AddItem "Goals"
.AddItem "Number"
End With
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.
ASKER
By the way, where will the 50 (or whatever) items be coming from?
hard coding it...
hard coding it...
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.
That would have made it a lot easier to populate the combobox and would avoid hard-coding.
ASKER
thanks very much
ASKER
.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