Create Searchbox Using Filter Function Automatically

How to create a searchbox using the Filter function automatically.

Here’s the recorded and cleaned code:

Option Explicit

Sub searchbox()

‘ searchbox Macro
‘ Searchable Drop Down List

Worksheets(“ClientNames”).Range(“C2”) = _
“=FILTER(Table1,ISNUMBER(SEARCH(DataEntry!B2,Table1,1)),””””)”
Sheets(“DataEntry”).Select
Range(“B2”).Select
Selection.ClearContents
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=”=ClientNames!$C$2#”
.IgnoreBlank = True
.InCellDropdown = True
‘ .InputTitle = “”
‘ .ErrorTitle = “”
‘.InputMessage = “”
‘.ErrorMessage = “”
.ShowInput = True
.ShowError = False
End With

End Sub

Let’s get some more details about the Excel functions Search, Isnumber and Filter.

The SEARCH function has the following syntax:

SEARCH(find_text,within_text,[start_num])

find_text: This parameter is required. This is the text that you want to find.
within_text: This parameter is required. This is the text in which you want to search for the value of the find_text argument.
start_num: This parameter is optional. This is the character number in the within_text argument at which you want to start searching.

The SEARCH function finds one text string within a second text string, and returns the number of the starting position of the first text string from the first character of the second text string. For example, to find the position of the letter “t” in the word “smith”, you can use the following function:
=SEARCH(“t”,”smith”)

This function returns 4 because “t” is the fourth character in the word “smith”.

You can also search for words within other words. For example, the function
=SEARCH(“base”,”database”)
returns 5, because the word “base” begins at the fifth character of the word “database”.

ISNUMBER belongs to the group of ‘IS’ functions which check the specified value and returns TRUE or FALSE depending on the outcome.

For example the syntax of this function is ISNUMBER(value) and ‘value’ refers to a number.

The FILTER function has the following Syntax: FILTER(array, include, [if_empty])

ARRAY: the cells that contain the data.

include – the cells that have the data and the match criteria.

[if_empty] – tells the function what should be displayed if the list does contain the searched items. In our example, it will display a blank or ’empty string’.

Further Reading:

How to use the Excel Filter Function