Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box Problem 1

Status
Not open for further replies.

caerdydd

Programmer
Mar 2, 2004
35
GB
Hi all
Very basic question. Using the control toolbox and the combo box function in excel. I have written the code -

Private Sub Workbook_Open()
With comList
.Clear
.AddItem "Media"
.AddItem "Banks"
.AddItem "Pharmaceuticals"
End With
End Sub

Which seems to work as no error message is retrieved but when i hit the drop down list on the combo box there is no data. does anyone have any idea as to why this is.
thanks for taking the time to read this
rgds
Caer
 
Try removing the items 1 by 1, starting with the last one and working up. This code should work:

Dim Total As Integer
Dim I as Integer
Total = listBox.ListCount
For I = Total To 1 Step -1
listBox.RemoveItem 0
Next I
 
Hi,

Your ComboBox needs an object -- either it's on a worksheet or a userform, for instance, if your ComboBox is in Sheet1...
Code:
Private Sub Workbook_Open()
  With Worksheets("Sheet1").comList
    .Clear
    .AddItem "Media"
    .AddItem "Banks"
    .AddItem "Pharmaceuticals"
  End With


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Skip
Thanks a lot, you tiggered the grey matter and its working good.
Very grateful
Caer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top