Lesson 62 of 92 · Free Excel Course
Excel · Excel function reference
Excel SEARCH Function: Syntax, Wildcards, Examples and Common Errors
How the Excel SEARCH function finds text in a cell, ignoring case: syntax, ? and * wildcards, contains tests, FILTER, highlighting, and #VALUE! fixes.
The SEARCH function finds where one piece of text starts inside another and returns that position as a number. =SEARCH("margin","Profit Margin") returns 8, even though the capital M doesn't match, because SEARCH ignores case. It also understands the wildcards ? and *, which makes it the go-to function for "does this cell mention X?" tests in IF, FILTER and conditional formatting. If the text isn't found you get #VALUE!. SEARCH is available in Excel for Microsoft 365 (Windows and Mac), Excel for the web, Excel 2024, Excel 2021, Excel 2019 and Excel 2016.
FIND or SEARCH? They take the same arguments. FIND is case-sensitive and has no wildcards; SEARCH ignores case and has them. And if you just want to search the sheet for a word, that's not a formula at all: press Ctrl+F (or Home > Editing > Find & Select > Find).
Syntax
=SEARCH(find_text, within_text, [start_num])
- find_text (required): the text you're looking for, in quotes or as a cell reference. Case is ignored. It can contain
?(any one character) and*(any run of characters); put~in front of either to search for the character itself. - within_text (required): the text to look in, usually a cell such as B2.
- start_num (optional): the character to start from. Left out, it is 1. Zero, a negative number, or a number larger than the length of within_text gives #VALUE!. The result is still counted from the first character.
Examples
Microsoft's example
These rows are the data from Microsoft's SEARCH page, with the results it lists.
| A | B | C | |
|---|---|---|---|
| 1 | Data | Formula | Result |
| 2 | Statements | =SEARCH("e",A2,6) | 7 |
| 3 | Profit Margin | =SEARCH(A4,A3) | 8 |
| 4 | margin | =REPLACE(A3,SEARCH(A4,A3),6,"Amount") | Profit Amount |
| 5 | The "boss" is here. | =MID(A3,SEARCH(" ",A3)+1,4) | Marg |
=SEARCH("e",A2,6)starts at character 6 of "Statements" and finds the e at 7. The first e, at 5, is skipped.=SEARCH(A4,A3)finds "margin" inside "Profit Margin" at 8, ignoring the capital M.- REPLACE uses that 8 as the place to swap 6 characters for "Amount", giving Profit Amount.
- MID starts one character after the space and takes 4: Marg.
- To find a double quotation mark, double it inside the quotes:
=SEARCH("""",A5)returns 5. Microsoft's page goes on to pull out boss, the text between the two quotes, with two SEARCHes inside MID.
Wildcards: ? and *
A question mark stands for exactly one character. Spellings of grey and gray, in any case, all match gr?y.
| A | B | C | |
|---|---|---|---|
| 7 | Item | Position | Grey or gray? |
| 8 | Light Grey Hoodie | 7 | TRUE |
| 9 | Gray Beanie | 1 | TRUE |
| 10 | Navy Scarf | #VALUE! | FALSE |
| 11 | GREY Socks | 1 | TRUE |
An asterisk stands for any number of characters, so it checks that two words appear in that order. =ISNUMBER(SEARCH("ship*late",A2)) is TRUE for "Shipped 3 days late" but FALSE for "Late shipment", where "late" comes first.
Contains a word: FILTER and highlighting
ISNUMBER(SEARCH(...)) works on a whole column at once inside FILTER, which spills every matching row. Here it pulls out each support ticket that mentions a refund, however it's typed.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Ticket | Note | Ticket | Note | |
| 2 | T-101 | Customer wants a REFUND | T-101 | Customer wants a REFUND | |
| 3 | T-102 | Login page is slow | T-103 | Refunded twice by mistake | |
| 4 | T-103 | Refunded twice by mistake | T-105 | Asked about refund policy | |
| 5 | T-104 | Change shipping address | |||
| 6 | T-105 | Asked about refund policy |
FILTER needs Excel for Microsoft 365, Excel 2021, Excel 2024 or Excel for the web. To color the matching rows instead (any version):
- Select A2:B6.
- Click Home > Styles > Conditional Formatting > New Rule.
- Choose Use a formula to determine which cells to format.
- Type
=ISNUMBER(SEARCH("refund",$B2)), click Format, pick a fill, and click OK twice.
The $ keeps every cell looking at column B. On a Mac, set the rule's Style to Classic first. The conditional formatting lesson covers this in full.
Finding a real ? or *
Because ? means "any character", =SEARCH("?",A21) returns 1 for any cell that isn't empty. Add a tilde to search for the character itself.
| A | B | C | D | |
|---|---|---|---|---|
| 20 | Comment | "?" | "~?" | "~*" |
| 21 | Is it waterproof? | 1 | 17 | #VALUE! |
| 22 | Fits size 10* | 1 | #VALUE! | 13 |
| 23 | Great fit | 1 | #VALUE! | #VALUE! |
Use "~~" for a real tilde. =FIND("?",A21) also works, since FIND has no wildcards.
Common errors
- #VALUE! because the text isn't there. Expected for a no-match. Wrap it in ISNUMBER for TRUE/FALSE, or IFERROR to show your own value:
=IFERROR(SEARCH("refund",B2),0). See Excel errors and fixes. - #VALUE! from start_num. A start_num of 0, a negative number, or one bigger than the length of the text is an error. Check the length with LEN.
- A match you didn't expect. A literal
?or*in find_text acts as a wildcard. Put~before it. - Every row matches. An empty search cell counts as "" and returns 1, so
ISNUMBER(SEARCH(D1,B2))is TRUE everywhere and FILTER returns all rows. Guard it:=IF(D1="",FALSE,ISNUMBER(SEARCH(D1,B2))). - Part of a word matches. "refund" also finds "Refunded", and "art" finds "Start". To match the whole word, pad both sides with spaces:
=ISNUMBER(SEARCH(" art "," "&B2&" ")). - The position is always 1. A leading
*(as in"*refund") matches from the first character. Drop it: SEARCH already looks anywhere in the cell. - #SPILL! from FILTER means the cells it needs aren't empty. Clear them.
- Capitals ignored when they matter. Use FIND or EXACT.
Related functions
- Text functions: the full lesson on LEFT, MID, SUBSTITUTE, TEXTBEFORE and friends.
- FIND function: the case-sensitive version, with no wildcards.
- LEN function: counts characters, handy with SEARCH and MID.
- Sort and filter: FILTER explained from the start.
Try it yourself
Download the practice workbook. The Practice sheet has yellow cells for Microsoft's examples, the gr?y wildcard test, a refund contains test with FILTER and a highlight rule, and literal ? and * searches. The Answers sheet has the working formulas and the finished highlight rule.
Frequently asked questions
Is the Excel SEARCH function case-sensitive?
No. SEARCH treats capital and small letters as the same, so =SEARCH("refund","REFUND due") returns 1. If you need capitals to matter, use the FIND function, which takes the same arguments but is case-sensitive.
How do I check if a cell contains a word in Excel?
Use =ISNUMBER(SEARCH("refund",B2)). SEARCH returns a position number when the word is there and #VALUE! when it isn't; ISNUMBER turns that into TRUE or FALSE. Wrap it in IF for your own labels: =IF(ISNUMBER(SEARCH("refund",B2)),"Yes","No").
How do I search for a question mark or asterisk with SEARCH?
Put a tilde in front of it: =SEARCH("~?",A2) finds a real question mark and =SEARCH("~*",A2) finds a real asterisk. Without the tilde, ? matches any single character and * matches any run of characters. FIND also works, because FIND doesn't use wildcards.
What wildcards does SEARCH support?
Two, plus an escape. A question mark (?) matches any one character, so gr?y finds grey and gray. An asterisk (*) matches any sequence of characters, so ship*late finds ship followed later by late. A tilde (~) before ? or * makes it a normal character.