Is it possible to create a search field 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.
As we saw in a previous post, Conditional Formatting needs a TRUE or FALSE to determine whether or not to apply the formatting. The SEARCH function returns a number if it finds what we are looking for, so we simply put it inside the ISNUMBER function, which gives us a TRUE if the result of the SEARCH formula is a number:
Select the cells you want to include in the search and click on Conditional Formatting from the Home ribbon and choose New Rule (Shortcut: Alt => H => L => N). Choose “Use a formula to determine which cells to format” and type the formula in the formula field.
If we type “RG” in the search field, all products with “RG” in the name will be highlighted! And it works with numbers too!
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:
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’m not going to explain how it works in this post.
(close with Ctrl+Shift+Enter and copy down)
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.
Author: Audun Danielsen