Combo Box created in code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All – I need to create a Combo Box in code. What is the code to create
a Combo Box?

Thanks
Paul
 
Worksheet combo?

Sub CreateCombobox()
'-----------------------------------------------------------------
Dim oWs As Worksheet
Dim oOLE As OLEObject

Set oWs = ActiveSheet

Set oOLE = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Combobox.1", _
Left:=200, Top:=100, Width:=80, Height:=32)


oOLE.ListFillRange = "A1:A10"

End Sub

'-----------------------------------------------------------------


Forms combo?

With ActiveSheet
.DropDowns.Add(372.75, 46.5, 300, 50).Select
Selection.ListFillRange = "B1:B3"
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Bob thanks for the info. However, I developed the following code using the
form tool. The only problem is when the code runs; an additional ‘Sub - End
Sub’ line of code is created.
Here is the code:
Private Sub UserForm_Initialize()

ComboBox1.ColumnCount = 5
ComboBox1.RowSource = "a1:e4"
ComboBox1.ControlSource = "a6"
'Place the ListIndex into cell a6
ComboBox1.BoundColumn = 0

End Sub

And here is the additional code line that is return after the above code is
finished.

Private Sub ComboBox1_Change()

End Sub

What changes are required to prevent the additional lines of code?

Thanks Again
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top