Autocomplete suggestion in Excel data validation list again

前端 未结 2 1234
一向
一向 2021-01-26 07:47

How to make suggestions in Excel data validation list while typing. There are constraints in my request:

  1. The list of items should be in another sheet, and must not
2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-26 08:23

    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
    

提交回复
热议问题