Autocomplete suggestion in Excel data validation list again

前端 未结 2 1233
一向
一向 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条回答
  • 2021-01-26 08:00

    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
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题