Search code examples
vbaexcelactivex

Sometimes the ActiveX Combobox only shows one row, why?


It seems that when I first click on the combobox and then click on the arrow, all items are displayed.

While if I click on the arrow without clicking on the combobox before, only one item is displayed and I can click on scroll buttons to see the other items.

Why does this happen?

Here is the macro I am using to populate the combobox with items

Private Sub ComboBox1_GotFocus()
    Dim c As Range
    Dim selText As String
    selText = ComboBox1.selText
    ComboBox1.Clear
    For Each c In wConfig.Range("BudgetDropdown").Cells
        ComboBox1.AddItem c.Value
    Next c
    ComboBox1.selText = selText
End Sub

enter image description here

enter image description here


Solution

  • To automatically populate combobox with data from named range, set it's ListFillRange property to the name of the range.

    You can do it at runtime:

    ComboBox1.ListFillRange = "BudgetDropdown"
    

    Or by setting it to BudgetDropdown in properties window.