Is it possible to create a search box in Excel, without using VBA?
Yes, and it’s easy!
We will use Conditional Formatting to highlight the fields that match the search string. For example, if you look at the table below, we want to highlight row 8, 11, 15 and 25 if we search for “RG”, because “RG” is part of the product name in those rows.
The secret is the SEARCH function. The SEARCH function looks for text within a text and returns its position. For example, the formula =SEARCH(“RD”,A5) will return 1, because it finds “RD” in the first position in the text in A5. If we search for “XX” instead, it would return #VALUE.
We will use Conditional Formatting to highlight the search results. Conditional Formatting needs a TRUE or FALSE to determine whether or not to apply the formatting. The SEARCH function, however, returns a number if it finds what we are looking for, so we have to put it inside the ISNUMBER function. That will give us a TRUE if the result of the SEARCH formula is a number:
Select the range you want to include in the search and click on Conditional Formatting from the Home ribbon and choose New Rule (or shortcut: Alt > H > L > N). Choose “Use a formula to determine which cells to format” and type the formula in the formula field.
OK, let’s try it and see if it works: If we type “RG” in the search field, all products with “RG” in the name will be highlighted! And it works with numbers too!
There is one problem with this formula, though. If you leave the search field empty, all cells will be highlighted. Here’s the workaround:
We use the AND function to add the additional criterion; that the search field must be empty for the function to be true. The syntax for “not empty” is <>“” (<> means not equal, and “” (2 double quotes) means empty or null). This is the formula we can use in Conditional Formatting to make it perfect:
Note: If you use comma as the decimal separator as default (applies to most non-English users) you have to replace the commas in the formulas with semicolons.
Read more useful Excel tricks here:
- Create a drop-down list in Excel in 3 minutes!
- Create a dynamic drop-down menu in Excel in 4 easy steps
- Highlight Cells in Excel that Contain a Formula
- How to Create an HTML Table with Excel
Bonus tip 1
How can we find out how many matches we got? Try this formula:
This is an array formula, so you have to close it with Ctrl+Shift+Enter
Bonus tip 2
Is it possible to create a list of results? Yes, but it’s not easy, so I’ll just give you the formula:
=IFERROR( IF( ROWS( $F5:F5)=SUM( –( ISNUMBER( SEARCH( $C$2,$A$5:$A$54)))),INDEX( $A$5:$A$54,SMALL( IF( ISNUMBER( SEARCH( $C$2,$A$5:$A$54)),ROW( $A$5:$A$54)-ROW( $A$5)+1),ROWS( F$5:F5))),””),””)
(close with Ctrl+Shift+Enter and copy down)
Are you using a non-English version of Excel? Click here for translations of the 100 most common functions.