Search code examples
excelvbacombobox

Why is my VBA ComboBox blank until I type


I created a simple UserForm ComboBox with a list of items:

Private Sub CourseComboBox_Change()
CourseComboBox.List = Sheets("Course Lists").Range("G2:G15").Value
End Sub

When I run the UserForm the drop down list appears empty until I type something. At this point the full list displays for me to choose from. Is there something I'm doing wrong that makes the text in my ComboBox not show up until I type?

I tried adding CourseComboBox.ListIndex = 0 (a previous solution on here), which had no effect.


Solution

  • I think the issue is that you're loading the contents of the Combobox when the combobox changes (i.e. the Combobox' Change event) where you should be loading the combobox on the UserForm_Initialize() event handler instead.

    Try moving this line:

    CourseComboBox.List = Sheets("Course Lists").Range("G2:G15").Value

    To here:

    Private Sub UserForm_Initialize()
        CourseComboBox.List = Sheets("Course Lists").Range("G2:G15").Value
    End Sub
    

    And delete the other CourseComboBox_Change() event code.