How to check if cell contains wildcard asterisk (*) character

Matthew Layton picture Matthew Layton · Nov 18, 2014 · Viewed 32k times · Source

Consider the following two formulas:

=IF(SEARCH("*", A1), "true", "false")

=IF(SEARCH(CHAR(42), A1), "true", "false")

I am using this to try and detect if a cell contains a * character, but this returns "true" for all cells. I can only assume that Excel sees * as a wildcard maybe.

How do you detect the existence of a * in Excel?

Answer

user3885927 picture user3885927 · Nov 18, 2014

According to this reference of microsoft you should be able to use ~

Microsoft Excel uses the tilde (~) as a marker to indicate that the next character is a literal. When you use the Find and Replace dialog box to find or replace a character such as a tilde (~), an asterisk (*), or a question mark (?), you must add a tilde (~) before the character in the Find what box.

So change =IF(SEARCH("*", A1), "true", "false") to =IF(SEARCH("~*", A1), "true", "false") and it should work.