4 PRO Ways to Create A Filtering Search Box [Excel Download]
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 1 How to create an Excel filtering search engine.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelFilteringSearchBox.png)
Creating A Search Box In Excel
It’s unfortunate Excel does not have a form control search box (maybe in the future?) as I could see that type of tool opening the doors to a ton of creative and time-saving functionalities. But luckily there are a few different methods you can use to create a search box on your own.
In this post, I will walk you through a number of different ways you can create a professional-looking search box interface that can filter to only show desired search results within a data range.
Examples Of What We’ll Create:
Here is a little preview of the search interfaces you will be able to create after working through this article. All these solutions are included in the free Excel File download at the end of this article.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 3 Excel Filter Search Box - Pick Column](https://thespreadsheetguru.com/wp-content/uploads/2022/10/Excel-Filter-Search-Box-Text-or-Number-Values-2.png)
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 5 Excel Filter Search Box - With VBA Code](https://thespreadsheetguru.com/wp-content/uploads/2022/10/Excel-Filter-Search-Box-With-VBA-Code-2.png)
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 7 Excel Filter Search Box - Text or Number Values](https://thespreadsheetguru.com/wp-content/uploads/2022/10/Excel-Filter-Search-Box-Search-All-Columns-2.png)
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 9 Excel Filter Search Box - Pick Column](https://thespreadsheetguru.com/wp-content/uploads/2022/10/Excel-Filter-Search-Box-Pick-Column-2.png)
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 11 Excel Filter Search Box - Search As You Type](https://thespreadsheetguru.com/wp-content/uploads/2022/10/Excel-Filter-Search-Box-Search-As-You-Type-2.png)
COMPATIBILITY NOTE: All non-VBA solutions will require the Filter Dynamic Array function. This function was released in Microsoft 365 and Excel 2021+.
Filtering Search Box – Single Column Search
In this section, you will learn how to create a filtering search box that provides results for an exact match result within a designated column of the data. You will also learn how to incorporate Option Buttons so that you have the flexibility to choose which column gets searched.
The end result will look something like this:
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 13 Excel filter search box with column selector](https://thespreadsheetguru.com/wp-content/uploads/2022/10/Excel-Filter-Search-Box-Pick-Column.png)
Spreadsheet Setup
In this example, the raw data is stored in a separate spreadsheet tab inside an Excel Table object (Ctrl + t). For clarity, I have renamed the table to DataTable.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 15 Excel Table Renaming](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelTableRenaming.png)
Table Header Formula
As part of this solution, you will need to either type out or bring over the header names from your source data table (in this example the Excel Table named DataTable). I chose to use a formula to dynamically bring over the heading names shown below.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 17 Dynamic Array Table Headers in Excel.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelDynamicArrayTableHeaders.png)
=DataTable[#Headers]
Option Buttons To Choose Search Column
You can add Option Buttons to provide your user with an easy way to predetermine which column they would like to search through.
To add an Option Button to your spreadsheet, you will need to navigate to your Developer Tab in the Excel Ribbon. Once the Developer tab has been selected, you will need to open the Insert menu button and click the Option Button icon. You can then proceed to draw an Option Button control on your spreadsheet.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 19 Insert form control option buttons with Excel Developer](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelInsertFormControlOptionButtons.png)
Once you’ve created an option button for each column you would like to search, you will likely want to change the label text to correspond with your data range’s column headings. You will need to ensure you align the order of your columns in the table with the order you created for the Option Buttons. For example, the header in Column 1 of your data range will be tied to the first Option Button you created on the spreadsheet.
If you would like to skip a column (for example, only search columns 1,2, & 4), create a total of 4 option buttons and hide the 3rd from sight, so your users cannot select it.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 21 Link option button to a cell in Excel](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelOptionButtonLinkToCell.png)
Lastly, you will need to link your Option Buttons to a cell on your spreadsheet. You can do this by
- Right-clicking one of your Option Buttons
- Select Format Control…
- Populate the Cell Link textbox
- Click OK
You will only need to do this one time as all Option Boxes on your spreadsheet will link to the same cell by default.
Table Body Formula For Filtered Data
Finally, you will need to write a formula for the search engine itself. This logic can be contained in a single Array Formula. There are 3 parts to this formula:
- Filter Function – The Filter function allows you to perform a logic test within a column of a data range and return only the rows that pass the test. There is an optional third input for if there are no search results found where we will return the text “No Results Found”.
- IsNumber/Search Functions – Since the Filter Function does not have a wildcard capability, there is a creative workaround we can use to give us this functionality. This allows us to perform partial-match or wildcard searches.
- Index Function – This controls which column is getting searched. Because it points its column input to the output of your Option Buttons, it will allow the IsNumber/Search combination to only look at a single column within your data table.
=FILTER(DataTable,ISNUMBER(SEARCH($C$2,INDEX(DataTable,0,$I$2))),"No Results!")
Here is how the search engine formula has been integrated into our example. Notice that both the Search cell and the Option Button link cell are both referenced within the formula.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 23 An Excel filter function formula example.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelFilterFunctionFormula.png)
Filtering Search Box – Multiple Column Search Formula
In this section, you will learn how to create a filtering search box that loops through each column of your data range until it finds a match.
The end result will look something like this:
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 25 Excel example of search box filter that searches all columns.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelFilterSearchBox-SearchAllColumns.png)
Spreadsheet Setup
In this example, the raw data is stored in a separate spreadsheet tab inside an Excel Table object (Ctrl + t). For clarity, I have renamed the table to DataTable.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 15 Excel Table Renaming](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelTableRenaming.png)
Table Header Formula
As part of this solution, you will need to either type out or bring over the header names from your source data table (in this example the Excel Table named DataTable). I chose to use a formula to dynamically bring over the heading names shown below.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 17 Dynamic Array Table Headers in Excel.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelDynamicArrayTableHeaders.png)
Table Body Formula For Filtered Data
Finally, you will need to write a formula for the search engine itself. This logic can be contained in a single Array Formula. There are 4 parts to this formula:
- Filter Function – The Filter function allows you to perform a logic test within a column of a data range and return only the rows that pass the test. There is an optional third input for if there are no search results found where we will return the text “No Results Found”.
- IsNumber/Search Functions – Since the Filter Function does not have a wildcard capability, there is a creative workaround we can use to give us this functionality. This allows us to perform partial-match or wildcard searches.
- Index Function – This controls which column is getting searched. Because it points its column input to the output of your Option Buttons, it will allow the IsNumber/Search combination to only look at a single column within your data table.
- Column Looping – To get a column looping or cycling effect for our search engine, we will actually need to perform our Filter Function multiple times (one for each column we wish to search through). Luckily, since the Filter function has an If_Empty input, we can simply execute another Filter function pointing to a new column if no results are found in the prior column.
Below is the formula used for our example. Notice the Filter function is repeated 5 times for the 5 columns in our data set. The formulas are the exact same except the Index function is referencing a different column number in each Filter function.
Ultimately, if there is nothing to filter after cycling through all five columns, a message stating “No Results!” is displayed to the user.
=FILTER(DataTable,ISNUMBER(SEARCH($C$2,INDEX(DataTable,0,1))),
FILTER(DataTable,ISNUMBER(SEARCH($C$2,INDEX(DataTable,0,2))),
FILTER(DataTable,ISNUMBER(SEARCH($C$2,INDEX(DataTable,0,3))),
FILTER(DataTable,ISNUMBER(SEARCH($C$2,INDEX(DataTable,0,4))),
FILTER(DataTable,ISNUMBER(SEARCH($C$2,INDEX(DataTable,0,5))),"No Results!")))))
Here is how the search engine formula has been integrated into our example.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 31 Example of Excel filter function formula loop.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelFilterFunctionFormula-Loop.png)
Filtering Search Box – As You Type
In this section, you will learn how to create a filtering search box that will provide filtered search results as you type in real-time. Similar to the prior solution, the search engine we build will loop through each column of your data until a match is found.
The end result will look something like this:
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 33 Excel example of a search box that filters results as you type.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelFilterSearchBox-SearchAsYouType.png)
Spreadsheet Setup
In this example, the raw data is stored in a separate spreadsheet tab inside an Excel Table object (Ctrl + t). For clarity, I have renamed the table to DataTable.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 15 Excel Table Renaming](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelTableRenaming.png)
Table Header Formula
As part of this solution, you will need to either type out or bring over the header names from your source data table (in this example the Excel Table named DataTable). I chose to use a formula to dynamically bring over the heading names shown below.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 17 Dynamic Array Table Headers in Excel.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelDynamicArrayTableHeaders.png)
Add ActiveX TextBox
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 39 Excel developer tool ActiveX textbox](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelInsertActiveXTextbox.png)
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 41 Excel ActiveX textbox properties menu](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelActiveXTextboxProperties.png)
Table Body Formula For Filtered Data
We are going to utilize the same exact Excel formula for our filtering engine as we did in the prior solution (you can find more details about the logic here). The only difference will be that instead of pointing the Search function to the search box in Cell C2, we are going to point it to the cell we linked our ActiveX Textbox to (in this example, Cell I2).
Here is how the search engine formula has been integrated into our example.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 43 Example of Excel filtering function formula cycling.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/ExcelFilterFunctionFormula-Cycle.png)
=FILTER(DataTable,ISNUMBER(SEARCH($I$2,INDEX(DataTable,0,1))),
FILTER(DataTable,ISNUMBER(SEARCH($I$2,INDEX(DataTable,0,2))),
FILTER(DataTable,ISNUMBER(SEARCH($I$2,INDEX(DataTable,0,3))),
FILTER(DataTable,ISNUMBER(SEARCH($I$2,INDEX(DataTable,0,4))),
FILTER(DataTable,ISNUMBER(SEARCH($I$2,INDEX(DataTable,0,5))),"No Results!")))))
Filtering Search Box – VBA Solution
Creating Your Search Box User Interface
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 45 Excel example of a search box setup.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/Search-Box-Setup.jpg)
Your search UI (user interface) can look however you want as long as there is a place for your user(s) to enter some text and a search button for them to click. The above image shows how I will typically create my UI. I use a nice clean textbox to hold the search text and a flat-styled, rounded rectangle shape for the button.
Get Fancy With Option Buttons
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 47 Excel example of selector options combined with a search box.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/image-asset.jpg)
Instead of only allowing your users to filter on a single column, why not let them search through a few? By integrating Option Buttons with your search box you can have your users specify which column they want to search in. To insert the Option Buttons you will need to
- Navigate to your Developer Tab in the Ribbon
- Click the Insert dropdown button in the Controls group
- Select the Option Button Form Control (first row, last icon)
- Your mouse should now look like crosshairs and you will just want to click somewhere on your spreadsheet to draw the Option Button
After you draw a couple of Option Buttons, you can drag them into place so that they are relatively close to your search box. You can use the alignment tools to make everything look professional with even spacing.
One Pitfall
The one pitfall that I could not seem to get around is the fact that after entering your search text, you need to click outside of the textbox before you can click on the Search button. There are two workarounds that I could think of:
- Instead of using a form control textbox, you can use either a Cell or ActiveX Textbox to hold the search text (I have lines of code in the below VBA macros commented out that can handle these situations)
- Assign a keyboard shortcut to execute the macro, alleviating the need to click the Search button
I typically go the shortcut route as I like having the ability to place my search box wherever I want on my spreadsheet. Also, ActiveX controls can sometimes be glitchy depending on which version of Office you are using, so beware if you end up using this route.
Naming Your Objects
The key to getting this code to work well is to set up your objects (aka form controls) properly. First, you will need to determine the name of the text box that is holding your search term. To do this, you need to select the text box and then look at the Name Box (which is located to the left of the Formula Bar).
Typically you will see a default name of “Text Box 1”, however, you can change this name to something more meaningful like “UserSearch”. Make sure you hit the Enter key immediately after typing in your new name to apply the name change! If you click outside of the Name Box before hitting enter, your text box will revert back to its previous name.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 51 Changing name of text box for Excel search box.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/image-asset-2.jpg)
For your Option Buttons, you will not need to change their object names (unless you really want to). You will, however, need to ensure that their text is verbatim with the data headings you will be filtering on. Notice how all my example Option Buttons have the exact same text as the headings in my data. This is EXTREMELY important as the VBA code below will be filtering based on the text associated with the selected Option Button.
Searching For Text Only
This macro will allow you to filter on any column with a text value within it. The macro uses an open-ended search (designated by the asterisk symbol before and after the search term). This means that you could search “whi” and the search would show any cell containing those 3 characters. If you want your search box to only filter on exactly what the user types, just remove the asterisks from the VBA code.
To set up this code with your data you will need to designate your data range for the variable DataRange and you will also need to modify your text box name inside the Shapes reference. If your data does not start in Column A you may need to add or subtract from the myField variable to ensure you are filtering on the correct column number associated with your data set.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 53 Excel example of custom filter search box made with VBA code.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/image-asset-3.gif)
Sub SearchBox()
'PURPOSE: Filter Data on User-Determined Column & Text
'SOURCE: www.TheSpreadsheetGuru.com
Dim myButton As OptionButton
Dim MyVal As Long
Dim ButtonName As String
Dim sht As Worksheet
Dim myField As Long
Dim DataRange As Range
Dim mySearch As Variant
'Load Sheet into A Variable
Set sht = ActiveSheet
'Unfilter Data (if necessary)
On Error Resume Next
sht.ShowAllData
On Error GoTo 0
'Filtered Data Range (include column heading cells)
Set DataRange = sht.Range("A4:E31") 'Cell Range
'Set DataRange = sht.ListObjects("Table1").Range 'Table
'Retrieve User's Search Input
mySearch = sht.Shapes("UserSearch").TextFrame.Characters.Text 'Control Form
'mySearch = sht.OLEObjects("UserSearch").Object.Text 'ActiveX Control
'mySearch = sht.Range("A1").Value 'Cell Input
'Loop Through Option Buttons
For Each myButton In ActiveSheet.OptionButtons
If myButton.Value = 1 Then
ButtonName = myButton.Text
Exit For
End If
Next myButton
'Determine Filter Field
On Error GoTo HeadingNotFound
myField = Application.WorksheetFunction.Match(ButtonName, DataRange.Rows(1), 0)
On Error GoTo 0
'Filter Data
DataRange.AutoFilter _
Field:=myField, _
Criteria1:="=*" & mySearch & "*", _
Operator:=xlAnd
'Clear Search Field
sht.Shapes("UserSearch").TextFrame.Characters.Text = "" 'Control Form
'sht.OLEObjects("UserSearch").Object.Text = "" 'ActiveX Control
'sht.Range("A1").Value = "" 'Cell Input
Exit Sub
'ERROR HANDLERS
HeadingNotFound:
MsgBox "The column heading [" & ButtonName & "] was not found in cells " & DataRange.Rows(1).Address & ". " & _
vbNewLine & "Please check for possible typos.", vbCritical, "Header Name Not Found!"
End Sub
Searching For Text & Numerical Values
This VBA code is the exact same setup as the previous code but it has a few extra lines added to handle both numerical and text inputs from your user.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 55 Searching for text and numbers with Excel filter box](https://thespreadsheetguru.com/wp-content/uploads/2022/10/image-asset-4.gif)
Sub SearchBox()
'PURPOSE: Filter Data on User-Determined Column & Text/Numerical value
'SOURCE: www.TheSpreadsheetGuru.com
Dim myButton As OptionButton
Dim SearchString As String
Dim ButtonName As String
Dim sht As Worksheet
Dim myField As Long
Dim DataRange As Range
Dim mySearch As Variant
'Load Sheet into A Variable
Set sht = ActiveSheet
'Unfilter Data (if necessary)
On Error Resume Next
sht.ShowAllData
On Error GoTo 0
'Filtered Data Range (include column heading cells)
Set DataRange = sht.Range("A4:E31") 'Cell Range
'Set DataRange = sht.ListObjects("Table1").Range 'Table
'Retrieve User's Search Input
mySearch = sht.Shapes("UserSearch").TextFrame.Characters.Text 'Control Form
'mySearch = sht.OLEObjects("UserSearch").Object.Text 'ActiveX Control
'mySearch = sht.Range("A1").Value 'Cell Input
'Determine if user is searching for number or text
If IsNumeric(mySearch) = True Then
SearchString = "=" & mySearch
Else
SearchString = "=*" & mySearch & "*"
End If
'Loop Through Option Buttons
For Each myButton In sht.OptionButtons
If myButton.Value = 1 Then
ButtonName = myButton.Text
Exit For
End If
Next myButton
'Determine Filter Field
On Error GoTo HeadingNotFound
myField = Application.WorksheetFunction.Match(ButtonName, DataRange.Rows(1), 0)
On Error GoTo 0
'Filter Data
DataRange.AutoFilter _
Field:=myField, _
Criteria1:=SearchString, _
Operator:=xlAnd
'Clear Search Field
sht.Shapes("UserSearch").TextFrame.Characters.Text = "" 'Control Form
'sht.OLEObjects("UserSearch").Object.Text = "" 'ActiveX Control
'sht.Range("A1").Value = "" 'Cell Input
Exit Sub
'ERROR HANDLERS
HeadingNotFound:
MsgBox "The column heading [" & ButtonName & "] was not found in cells " & DataRange.Rows(1).Address & ". " & _
vbNewLine & "Please check for possible typos.", vbCritical, "Header Name Not Found!"
End Sub
Linking Your VBA Code To The Search Button
Once you have added your VBA code to your spreadsheet and are ready to see it in action, you will need to turn your search button into a trigger for your macro code. To do this, simply right-click on your button and select Assign Macro. The Assign Macro Dialog Box will pop up and you will want to find & select your macro’s name (in this case “Searchbox”). Once you have highlighted your macro name and clicked OK, every time you click your search button your filtering macro will run.
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 57 Adding VBA Macro code that creates a filter search button.](https://thespreadsheetguru.com/wp-content/uploads/2022/10/Add-VBA-Macro-Code-To-Filtering-Search-Button.png)
Creating A “Clear Filter” Button
You may want to add a feature to clear your filter on your search data. All you need to do is create another button and link the below code to your Clear Filter button
Sub ClearFilter()
'PURPOSE: Clear all filter rules
'Clear filters on ActiveSheet
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
End Sub
![4 PRO Ways to Create A Filtering Search Box [Excel Download] 59 Clear filter button in Excel](https://thespreadsheetguru.com/wp-content/uploads/2022/10/Clear-Filter-Button.png)
Get The Example File
If you would like to get a copy of the Excel file I used throughout this article, feel free to directly download the file by clicking the download button below.
Learn my best Excel chart design hacks. These will turn your ugly charts into professionally crafted graphics, leaving your boss speechless!!!

Keep Learning
Chris Newman
Chris is a finance professional and Excel MVP recognized by Microsoft since 2016. With his expertise, he founded TheSpreadsheetGuru blog to help fellow Excel users, where he shares his vast creative solutions & expertise. In addition, he has developed over 7 widely-used Excel Add-ins that have been embraced by individuals and companies worldwide.