View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Loading Sheet Names into Combo Box

I look at your code and saw CommandButton1_click rather than
Combobox1_click - my inattention.

The reason it doesn't stay loaded as you say, it because you rebuild the
list on the click event. When the list is rebuilt, the selection is
removed.

'This loads the ComboBox list
Private Sub ComboBox1_Click()
Dim Sh As Worksheet
Dim sVal as String
With ComboBox1
sVal = .Text
Clear
For Each Sh In ActiveWorkbook.Sheets
If Sh.Name < "Inputs" Then
AddItem Sh.Name
End If
Next
.Value = sVal
End With
End Sub

Should do it. Click event would be proper. I assume you are rebuilding
the list because there might be sheets added.

--
Regards,
Tom Ogilvy

"ExcelMonkey " wrote in message
...
So Tom, when I use this code, the combo box pulls the sheets into the
list as I click onto the combo box button. Afer the click is
completed, the chosen item from the list does not stay show up in the
box. That is, it loads it into the list, allow me to pick it, but does
display the chosen item int eh box after the click.

Is click the right event? Or should it be a Change event?




'This loads the ComboBox list
Private Sub ComboBox1_Click()
Dim Sh As Worksheet

With ComboBox1
Clear
For Each Sh In ActiveWorkbook.Sheets
If Sh.Name < "Inputs" Then
AddItem Sh.Name
End If
Next
End With
End Sub


---
Message posted from http://www.ExcelForum.com/