How to make suggestions in Excel data validation list while typing. There are constraints in my request:
- The list of items should be in another sheet, and must not be above in hidden rows.
- Typing a phrase should narrow the list to all the items which contain the phrase.
- Search should be case insensitive.
So after typing am
we should hypothetically have a suggestion to pick up from Amelia
, Camila
, Samantha
, provided that those girls' names are on the item list.
I have found a good solution here, however it does not filter the items with contains
clause but begins with
. I sum up the proposed solution here shortly.
- We insert a Combo Box (ActiveX Control) to a sheet.
We right click on a sheet name > View code > and paste the VBA code in the sheet VBA editor:
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
I could not find a way to modify to change the search option from 'begins with' to contains
.
The questions about autocomplete or autosuggest in validation list have been asked so far.
Excel data validation with suggestions/autocomplete
Excel 2010: how to use autocomplete in validation list
But neither of them contained answers which would satisfied the constraints I imposed.
Test file for download is here.