I know this is a very old topic but after googling a lot I still couldn’t find a working solution. I have a active x combobox in my worksheet “home” ,where the item source range is “itemlist” C2:C100. When I write “Ab” to the combobox search-text area I want that automaticaly the items starting with “Ab” are filtered and shown in the dropdown list (without extra expanding the dropdown). I have found following solution that works partial.
The items are filtered corectly but the problem is when I Write “Ab” lets say 5 items are filtered, but the item list row lenght is always 1, although I would expect 4. That means I have to scroll always to find the item.
Additionaly it seems that a second dropdown is always opened in parallel that is empty.
My vba code: (Called in sheet “Home” ComboBox1 Keyup event)
Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim searchText As String
Dim ws As Worksheet
Dim allItems As Variant
Dim filteredItems As Collection
Dim item As Variant
Dim i As Long
' Set the worksheet containing the original list of items
Set ws = ThisWorkbook.Sheets("itemlist")
' Get the search text from the ComboBox
searchText = ComboBox1.Text
' Get the full list of items from a range in the worksheet
allItems = ws.Range("C2:C100").Value
' Initialize a collection to store filtered items
Set filteredItems = New Collection
' Filter items based on the search text
On Error Resume Next
For i = 1 To UBound(allItems, 1)
If LCase(Left(allItems(i, 1), Len(searchText))) = LCase(searchText) Then
filteredItems.Add allItems(i, 1)
End If
Next i
On Error GoTo 0
' Clear and update the ComboBox with the filtered items
ComboBox1.Clear
For Each item In filteredItems
ComboBox1.AddItem item
Next item
' Restore the user's search text in the ComboBox
ComboBox1.Text = searchText
ComboBox1.SelStart = Len(searchText) ' Keep the cursor at the end of the text
' Automatically display the dropdown list
If filteredItems.Count > 0 Then
ComboBox1.ListRows = WorksheetFunction.Min(filteredItems.Count, 4)
ComboBox1.dropDown
End If
End Sub
2