22
votes

Apologies for my low level of Excel understanding, maybe what I am looking to do is not possible.

I have a list of 120 entries that I want to use as data validation. But instead of people having to scroll down the 120 options it would be great if they can start typing and see the options that could match what they are willing to write. Kind of like in autocomplete, I have found this tip.

I would like to have more options when the typing starts.

For example this would be a part of the list:

Awareness  
Education  
Budget  
Budget Planning  
Enterprise Budget 

When typing "B" I would like the three last options to appear and to click one of them. I don't know if there is a way of include vlookup in here...

Ideally the perfect thing would be to have several "tags" in one cell, but I fear that is absolutely impossible with excel.

Thank you very much for any input and sorry if I haven't explained myself properly.

8
When you are in the edit mode in excel, almost everything comes to a stop in Excel. You can capture keypress in Edit mode but then that is of no use as you need to show a dropdown list with the filtered values which is not possible in edit mode.Siddharth Rout
Having said that, there is an alternative. You could show a userform with a combobox when a user selects a cell and there you could achieve what you want. This way you will not have to create multiple comboboxes on the sheet if you have many cells with datavalidation. This will involve little bit of code as the userform has to be of the right size and needs to be placed on top of the cell.Siddharth Rout
Dear @Siddharth, thanks for the tips, I have discovered a whole new world with the userforms. I think I am going to use one to enter the data and put checkboxes with the tags, although they are way too many so I am going to try to put a combobox that can look up in a list, maybe you can help me with ideas. Many thanks again.gcv
Thanks @KazJaw for the editing.gcv

8 Answers

5
votes

If you don't want to go down the VBA path, there is this trick from a previous question.

Excel 2010: how to use autocomplete in validation list

It does add some annoying bulk to the top of your sheets, and potential maintenance (should you need more options, adding names of people from a staff list, new projects etc.) but works all the same.

5
votes

ExtendOffice.com offers a VBA solution that worked for me in Excel 2016. Here's my description of the steps. I included additional details to make it easier. I also modified the VBA code slightly. If this doesn't work for you, retry the steps or check out the instructions on the ExtendOffice page.

  1. Add data validation to a cell (or range of cells). Allow = List. Source = [the range with the values you want for the auto-complete / drop-down]. Click OK. You should now have a drop-down but with a weak auto-complete feature.

    enter image description here

  2. With a cell containing your newly added data validation, insert an ActiveX combo box (NOT a form control combo box). This is done from the Developer ribbon. If you don't have the Developer ribbon you will need to add it from the Excel options menu.

    enter image description here

  3. From the Developer tab in the Controls section, click "Design Mode". Select the combo box you just inserted. Then in the same ribbon section click "Properties". In the Properties window, change the name of the combo box to "TempComboBox".

    enter image description here

  4. Press ALT + F11 to go to the Visual Basic Editor. On the left-hand side, double click the worksheet with your data validation to open the code for that sheet. Copy and paste the following code onto the sheet. NOTE: I modified the code slightly so that it works even with Option Explicit enabled at the top of the sheet.

    Option Explicit
    
    Private Sub Worksheet_SelectionChange(ByVal target As Range)
    'Update by Extendoffice: 2018/9/21
    ' Update by Chris Brackett 2018-11-30
    
    Dim xWs As Worksheet
    Set xWs = Application.ActiveSheet
    
    On Error Resume Next
    
    Dim xCombox As OLEObject
    Set xCombox = xWs.OLEObjects("TempCombo")
    
    ' Added this to auto select all text when activating the combox box.
    xCombox.SetFocus
    
    With xCombox
        .ListFillRange = vbNullString
        .LinkedCell = vbNullString
        .Visible = False
    End With
    
    
    Dim xStr As String
    Dim xArr
    
    
    If target.Validation.Type = xlValidateList Then
        ' The target cell contains Data Validation.
    
        target.Validation.InCellDropdown = False
    
    
        ' Cancel the "SelectionChange" event.
        Dim Cancel As Boolean
        Cancel = True
    
    
        xStr = target.Validation.Formula1
        xStr = Right(xStr, Len(xStr) - 1)
    
        If xStr = vbNullString Then Exit Sub
    
        With xCombox
            .Visible = True
            .Left = target.Left
            .Top = target.Top
            .Width = target.Width + 5
            .Height = target.Height + 5
            .ListFillRange = xStr
    
            If .ListFillRange = vbNullString Then
                xArr = Split(xStr, ",")
                Me.TempCombo.List = xArr
            End If
    
            .LinkedCell = target.Address
    
        End With
    
        xCombox.Activate
        Me.TempCombo.DropDown
    
    End If
    End Sub
    
    Private Sub TempCombo_KeyDown( _
                    ByVal KeyCode As MSForms.ReturnInteger, _
                    ByVal Shift As Integer)
        Select Case KeyCode
            Case 9  ' Tab key
                Application.ActiveCell.Offset(0, 1).Activate
            Case 13 ' Pause key
                Application.ActiveCell.Offset(1, 0).Activate
        End Select
    End Sub
    
  5. Make sure the the "Microsoft Forms 2.0 Object Library" is referenced. In the Visual Basic Editor, go to Tools > References, check the box next to that library (if not already checked) and click OK. To verify that it worked, go to Debug > Compile VBA Project.

  6. Finally, save your project and click in a cell with the data validation you added. You should see a combo box with a drop-down list of suggestions that updates with each letter you type.

enter image description here

enter image description here

3
votes

There's a messy workaround at http://www.ozgrid.com/Excel/autocomplete-validation.htm that basically works like this:

  1. Enable "Autocomplete for Cell Values" on Tools - Options > Edit;
  2. Recreate the list of valid items on the cell immediately above the one with the validation criteria;
  3. Hide the lines with the list of valid items.
3
votes

This is a solution how to make autocomplete drop down list with VBA :


Firstly you need to insert a combo box into the worksheet and change its properties, and then running the VBA code to enable the autocomplete.

  1. Get into the worksheet which contains the drop down list you want it to be autocompleted.

  2. Before inserting the Combo box, you need to enable the Developer tab in the ribbon.

a). In Excel 2010 and 2013, click File > Options. And in the Options dialog box, click Customize Ribbon in the right pane, check the Developer box, then click the OK button.

b). In Outlook 2007, click Office button > Excel Options. In the Excel Options dialog box, click Popular in the right bar, then check the Show Developer tabin the Ribbon box, and finally click the OK button.

  1. Then click Developer > Insert > Combo Box under ActiveX Controls.

  2. Draw the combo box in current opened worksheet and right click it. Select Properties in the right-clicking menu.

  3. Turn off the Design Mode with clicking Developer > Design Mode.

  4. Right click on the current opened worksheet tab and click View Code.

  5. Make sure that the current worksheet code editor is opened, and then copy and paste the below VBA code into it.

Code borrowed from extendoffice.com

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Update by Extendoffice: 2018/9/21
    Dim xCombox As OLEObject
    Dim xStr As String
    Dim xWs As Worksheet
    Dim xArr



    Set xWs = Application.ActiveSheet
    On Error Resume Next
    Set xCombox = xWs.OLEObjects("TempCombo")
    With xCombox
        .ListFillRange = ""
        .LinkedCell = ""
        .Visible = False
    End With
    If Target.Validation.Type = 3 Then
        Target.Validation.InCellDropdown = False
        Cancel = True
        xStr = Target.Validation.Formula1
        xStr = Right(xStr, Len(xStr) - 1)
        If xStr = "" Then Exit Sub
        With xCombox
            .Visible = True
            .Left = Target.Left
            .Top = Target.Top
            .Width = Target.Width + 5
            .Height = Target.Height + 5
            .ListFillRange = xStr
            If .ListFillRange = "" Then
                xArr = Split(xStr, ",")
                Me.TempCombo.List = xArr
            End If
            .LinkedCell = Target.Address
        End With
        xCombox.Activate
        Me.TempCombo.DropDown
    End If
End Sub

Private Sub TempCombo_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    Select Case KeyCode
        Case 9
            Application.ActiveCell.Offset(0, 1).Activate
        Case 13
            Application.ActiveCell.Offset(1, 0).Activate
    End Select
End Sub
  1. Click File > Close and Return to Microsoft Excel to close the Microsoft Visual Basic for Application window.

  2. Now, just click the cell with drop down list, you can see the drop-down list is displayed as a combo box, then type the first letter into the box, the corresponding word will be completed automatically.

Note: This VBA code is not applied to merged cells.

Source : How To Autocomplete When Typing In Excel Drop Down List?

1
votes

None of the above mentioned solution worked. The one that seemed to work only provide the functionality for just one cell

Recently I had to enter a lot of names and without suggestions, it was a huge pain. I was fortunate enough to have this excel autocomplete add-in to enable the autocompletion. The down side is that you need to enable macro (but you can always turn it off later)

0
votes

I adapted the answer by ChrisB. Like in his example a temporary combobox is made visible when a cell is clicked. Additionally:

  1. List of Combobox items is updated as user types, only matching items are displayed
  2. if any item from combobox is selected, filtering is skipped as it makes sense and because of this error

Option Explicit

Private Const DATA_RANGE = "A1:A16"
Private Const DROPDOWN_RANGE = "F2:F10"
Private Const HELP_COLUMN = "$G"


Private Sub Worksheet_SelectionChange(ByVal target As Range)
    Dim xWs As Worksheet
    Set xWs = Application.ActiveSheet
    
    On Error Resume Next
    
    With Me.TempCombo
        .LinkedCell = vbNullString
        .Visible = False
    End With
    
    If target.Cells.count > 1 Then
        Exit Sub
    End If
    
    Dim isect As Range
    Set isect = Application.Intersect(target, Range(DROPDOWN_RANGE))
    If isect Is Nothing Then
       Exit Sub
    End If
       
    With Me.TempCombo
        .Visible = True
        .Left = target.Left - 1
        .Top = target.Top - 1
        .Width = target.Width + 5
        .Height = target.Height + 5
        .LinkedCell = target.Address

    End With

    Me.TempCombo.Activate
    Me.TempCombo.DropDown
End Sub

Private Sub TempCombo_Change()
    If Me.TempCombo.Visible = False Then
        Exit Sub
    End If
    
    Dim currentValue As String
    currentValue = Range(Me.TempCombo.LinkedCell).Value
    
    If Trim(currentValue & vbNullString) = vbNullString Then
        Me.TempCombo.ListFillRange = "=" & DATA_RANGE
    Else
        If Me.TempCombo.ListIndex = -1 Then
             Dim listCount As Integer
             listCount = write_matching_items(currentValue)
             Me.TempCombo.ListFillRange = "=" & HELP_COLUMN & "1:" & HELP_COLUMN & listCount
             Me.TempCombo.DropDown
        End If

    End If
End Sub


Private Function write_matching_items(currentValue As String) As Integer
    Dim xWs As Worksheet
    Set xWs = Application.ActiveSheet

    Dim cell As Range
    Dim c As Range
    Dim firstAddress As Variant
    Dim count As Integer
    count = 0
    xWs.Range(HELP_COLUMN & ":" & HELP_COLUMN).Delete
    With xWs.Range(DATA_RANGE)
        Set c = .Find(currentValue, LookIn:=xlValues)
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
              Set cell = xWs.Range(HELP_COLUMN & "$" & (count + 1))
              cell.Value = c.Value
              count = count + 1
             
              Set c = .FindNext(c)
              If c Is Nothing Then
                GoTo DoneFinding
              End If
           Loop While c.Address <> firstAddress
        End If
DoneFinding:
    End With
    
    write_matching_items = count

End Function

Private Sub TempCombo_KeyDown( _
                ByVal KeyCode As MSForms.ReturnInteger, _
                ByVal Shift As Integer)

    Select Case KeyCode
        Case 9  ' Tab key
            Application.ActiveCell.Offset(0, 1).Activate
        Case 13 ' Pause key
            Application.ActiveCell.Offset(1, 0).Activate
    End Select
End Sub

Notes:

  1. ComboBoxe's MatchEntry must be set to 2 - fmMatchEntryNone. Don't forget to set ComboBox name to TempCombo
  2. I am using listFillRange to set ComboBox options. The range must be continuous, so, matching items are stored in a help column.
  3. I have tried accomplishing the same with ComboBox.addItem, but it turned out to be hard to repaint list box as user types
0
votes
0
votes

The web version of Excel has this functionality. If you add list based validation, when you start typing in the cell it will popup a list of any matching items from the list.