Clear entries on Combo box

C

casey

I found code below while searching the net. It works, but how do you clear
the entry from the list when workbook is opened. For some reason, the
cboMonth says "August" instead of blank?

Private Sub Workbook_Open()
With Sheet1.cboName
.ListFillRange = ""
.AddItem "John"
.AddItem "Jay"
.AddItem "Mark"
.AddItem "Matt"
.ListIndex = 0
End With
End Sub


Private Sub cboName_Change()
For IndexNbr = cboMonth.ListCount - 1 To 0 Step -1
cboMonth.RemoveItem (IndexNbr)
Next IndexNbr

Select Case cboName.Value

Case "John"
cboMonth.AddItem "Jan"
cboMonth.AddItem "February"
cboMonth.AddItem "March"

Case "Jay"
cboMonth.AddItem "April"
cboMonth.AddItem "May"
cboMonth.AddItem "June"

Case "Mark"
cboMonth.AddItem "July"
cboMonth.AddItem "August"
cboMonth.AddItem "September"

Case "Matt"
cboMonth.AddItem "October"
cboMonth.AddItem "November"
cboMonth.AddItem "December"
Case Else
MsgBox cboName.Value & " Is Not Valid."

End Select
End Sub
 
D

Dave Peterson

If August is the value in that cboMonth box, then it's never being reset. It's
just the last value you had in that combobox when the workbook was saved.

Try clearing the cboMonth in the workbook_open event:

Option Explicit
Private Sub Workbook_Open()

Sheet1.cboMonth.Clear
Sheet1.cboMonth.Value = ""

With Sheet1.cboName
.ListFillRange = ""
.AddItem "John"
.AddItem "Jay"
.AddItem "Mark"
.AddItem "Matt"
.ListIndex = 0
End With

End Sub
 

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

Top