Autocomplete suggestion in Excel data validation list again

烂漫一生 提交于 2019-12-02 11:38:10

Try to add the following event (additionally the the other 2). Every time you enter something the code refreshes the ComboBox list.

Private Sub TempCombo_Change()
    With Me.TempCombo
        If Not .Visible Then Exit Sub
        .Clear 'needs property MatchEntry set to 2 - fmMatchEntryNone
        .Visible = False 'to refresh the drop down
        .Visible = True
        .Activate
        Dim xStr As String, xArr As Variant
        xStr = TempCombo.TopLeftCell.Validation.Formula1
        xStr = Right(xStr, Len(xStr) - 1)
        xArr = Split(xStr, Application.International(xlListSeparator))
        Dim itm As Variant
        For Each itm In xArr
            If InStr(1, itm, .Value, vbTextCompare) > 0 Or .Value = "" Then
                .AddItem itm
            End If
        Next itm
        .DropDown
    End With
End Sub

To overcome your first constraint, maybe you can assign a range to your combo box:

Dim xCombox             As OLEObject
    Dim xStr                As String
    Dim xWs                 As Worksheet
    Dim xArr
    Dim i                   As Range

    Set xWs = Application.ActiveSheet
    On Error Resume Next
    Set xCombox = xWs.OLEObjects("Combotest")
    With Sheets("Test_list2")
    Set i = .Range("A2:A" & .Range("A" & .Rows.Count).End(xlUp).Row)
    End With
    Combotest.ListFillRange = i.Address
 Set xWs = Application.ActiveSheet
    On Error Resume Next
    Set xCombox = xWs.OLEObjects("Combotest")
    With xCombox
        .LinkedCell = "F2"
        .Visible = True
    End With
.
.
.
.
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!