Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Clear entries on Combo box

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


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Clear entries on Combo box

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

casey wrote:

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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to populate worksheet from 2 combo boxes jswasson Excel Worksheet Functions 0 July 7th 06 01:21 PM
Macro that can run combo boxes simonsmith Excel Discussion (Misc queries) 0 June 5th 06 05:00 PM
Using control to clear spreadsheet dvonj Excel Discussion (Misc queries) 11 March 20th 06 10:29 AM
dynamic combo boxes tjb Excel Worksheet Functions 2 January 25th 05 07:33 PM
How do I autofill combo boxes with their destination cell? Defoes Right Boot Excel Worksheet Functions 3 January 10th 05 12:49 PM


All times are GMT +1. The time now is 05:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"