searchable combo box with a list of sugggestion on a userform

后端 未结 1 1704
难免孤独
难免孤独 2021-01-15 22:18

I have a user form and some combo boxes with drop down lists. However one of the combo boxes has almost 1000 items in the drop down and I\'d like the user to be able to star

相关标签:
1条回答
  • 2021-01-15 22:52

    You may try something like this...

    Place the following code on UserForm Module. Change the Sheet and Range references if required.

    Private Sub cboProgrammeName_Change()
    Dim ws As Worksheet
    Dim x, dict
    Dim i As Long
    Dim str As String
    Set ws = Sheets("XXX")
    x = ws.Range("ProgrammeNameList").Value
    Set dict = CreateObject("Scripting.Dictionary")
    str = Me.cboProgrammeName.Value
    If str <> "" Then
        For i = 1 To UBound(x, 1)
            If InStr(LCase(x(i, 1)), LCase(str)) > 0 Then
                dict.Item(x(i, 1)) = ""
            End If
        Next i
        Me.cboProgrammeName.List = dict.keys
    Else
        Me.cboProgrammeName.List = x
    End If
    Me.cboProgrammeName.DropDown
    End Sub
    
    0 讨论(0)
提交回复
热议问题