If a cell contains text in Excel
To show "Refund" when a note in B2 mentions a refund anywhere in it, use =IF(ISNUMBER(SEARCH("refund",B2)),"Refund",""). SEARCH looks for the word inside the text, ISNUMBER turns "found it" into TRUE, and IF shows what you want. It works in every version of Excel, on Windows and Mac, and in Excel for the web.
The formulas at a glance
| You want | Formula | Notes |
|---|---|---|
| A value if the cell contains a word | =IF(ISNUMBER(SEARCH("refund",B2)),"Refund","") | Capitals don't matter |
| The same, shorter | =IF(COUNTIF(B2,"*refund*"),"Refund","") | The * on both sides means "anything before or after" |
| Capitals must match too | =IF(ISNUMBER(FIND("RF-",B2)),"Yes","") | FIND cares about capitals; SEARCH doesn't |
| The word to look for is in a cell | =ISNUMBER(SEARCH($E$1,A2)) | Lock the cell with $ before you copy down |
| Either of two words | =IF(OR(ISNUMBER(SEARCH("refund",B2)),ISNUMBER(SEARCH("money back",B2))),"Refund","") | Use AND when it must contain both |
| Any text at all, where a number doesn't count | =IF(ISTEXT(B2),"Text","") | For "is there any text in this cell?" |
| How many cells contain it | =COUNTIF(B2:B11,"*refund*") | No flag column needed |
Each one is worked through below.
A worked example
A support team keeps a note of every call. You want a flag on every call that mentions a refund, wherever the word is and whatever the capitals.
SEARCH tells you where the word starts. In "Refund sent on Friday" it starts at the 1st character. In "Customer wants a refund", count the letters and spaces: "Customer wants a " is 17 characters, so refund starts at the 18th. When the word isn't there, SEARCH gives the error #VALUE!.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Note | SEARCH | ISNUMBER | Flag |
| 2 | Refund sent on Friday | 1 | TRUE | Refund |
| 3 | Customer wants a refund | 18 | TRUE | Refund |
| 4 | Delivery delayed again | #VALUE! | FALSE |
A number means found, and the error means not found. ISNUMBER asks "is this a number?", which turns the answer into TRUE or FALSE. IF then shows "Refund" for TRUE and nothing for FALSE. Put the three steps together and you get one formula:
=IF(ISNUMBER(SEARCH("refund",B2)),"Refund","")
SEARCH("refund",B2)looks for refund in B2. Capitals don't matter.ISNUMBER(…)is TRUE when SEARCH found it."Refund",""is what to show when it's found, and when it isn't (""leaves the cell looking empty).
The value to return can be anything: a number such as 1, a word, or another cell, such as =IF(ISNUMBER(SEARCH("refund",B2)),C2,0) to bring back the amount only on refund rows.
Another way: COUNTIF with wildcards
The * wildcard stands for "any text, or none". So "*refund*" means refund with anything before it and anything after it. COUNTIF on a single cell gives 1 if it matches and 0 if not, and IF treats 1 as TRUE:
=IF(COUNTIF(B2,"*refund*"),"Refund","")
Both give the same answer. COUNTIF is shorter, and SEARCH is easier to build on, as the next sections show. Leave out the first * and COUNTIF only finds notes that start with refund.
Look for the word typed in a cell
Type the word into E1 and point the formula at it, so anyone can change what it looks for. Lock E1 with $ so it stays put when you copy the formula down (see locking a cell with $):
=ISNUMBER(SEARCH($E$1,A2))
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Note | Found? | With COUNTIF | Look for | delivery |
| 2 | Delivery delayed again | TRUE | Yes | ||
| 3 | Refund sent on Friday | FALSE | No | ||
| 4 | Changed delivery address | TRUE | Yes | ||
| 5 | Left a voicemail | FALSE | No |
On its own, without IF, the SEARCH version shows TRUE or FALSE, which is handy for filtering. With COUNTIF, join the wildcards on with &: "*"&$E$1&"*". Type another word in E1 and both columns change.
Any of several words, or both
To flag notes that mention a refund or money back, put two SEARCH checks inside OR. To flag only the notes that mention both a refund and the manager, use AND:
| A | B | C | |
|---|---|---|---|
| 1 | Note | Refund or money back | Refund and manager |
| 2 | Refund agreed by manager | Flag | Flag |
| 3 | Wants their money back | Flag | |
| 4 | Refund sent on Friday | Flag | |
| 5 | Asked for the manager |
With OR, any one of the words is enough, so three of the four notes are flagged. With AND, the note must have both, so only the first one is.
Capitals that matter: FIND
FIND works like SEARCH but cares about capitals. That's what you want for codes, where "RF-" is a refund code and "rf-" isn't. For everyday words, SEARCH is safer:
| A | B | C | |
|---|---|---|---|
| 1 | Note | SEARCH | FIND |
| 2 | Refund sent on Friday | TRUE | FALSE |
| 3 | Customer wants a refund | TRUE | TRUE |
| 4 | REFUND agreed by manager | TRUE | FALSE |
To make the capitals the same in the notes themselves, see changing case.
If a cell has any text in it
Sometimes "contains text" means "has words in it, as opposed to a number or nothing". ISTEXT is TRUE for text and FALSE for numbers and empty cells. To test for anything at all, number or text, use A2<>"". Here the entries are in column A:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Entry | ISTEXT | Not empty | Flag |
| 2 | Paid | TRUE | TRUE | Text |
| 3 | 125 | FALSE | TRUE | |
| 4 | FALSE | FALSE | ||
| 5 | TBC | TRUE | TRUE | Text |
This is how to spot a "TBC" or "n/a" typed into a column of figures before it causes a #VALUE! error. A number stored as text counts as text here too, which is often exactly what you want to find.
Count them, or colour them
To count how many notes mention a refund, you don't need a flag column at all: =COUNTIF(B2:B11,"*refund*") (more in counting cells with text).
To colour the whole row instead, select the rows, then go to Home › Conditional Formatting › New Rule and choose Use a formula to determine which cells to format. On a Mac, in the New Formatting Rule box, set Style to Classic first, then choose that option. Type =ISNUMBER(SEARCH("refund",$B2)), with the $ before B so every cell on the row looks at the note. Conditional formatting with a formula has more.
Common mistakes
#VALUE! on the rows without the word
=IF(SEARCH("refund",B2),"Refund","") works for the notes that mention a refund, and gives #VALUE! for all the others, because SEARCH's error goes straight through IF. Wrap SEARCH in ISNUMBER.
Using = with the word
=IF(B2="refund","Refund","") is only TRUE when the whole cell says refund and nothing else. And =IF(B2="*refund*",…) doesn't work either: the = sign doesn't understand wildcards. Only functions such as COUNTIF, SUMIF, MATCH, VLOOKUP and XLOOKUP do.
Part of a longer word
SEARCH finds the letters anywhere, so looking for "ref" also finds "referral" and "preferred". Search for the whole word, or add spaces round it: " ref ".
Spaces you can't see
Searching for "refund " with a space misses "a refund" at the very end of a note. Take the space out of the word you search for. If the word is typed in a cell, tidy it inside the formula with TRIM: =ISNUMBER(SEARCH(TRIM($E$1),A2)).
Try it now
In C2, show Refund next to every note that mentions a refund anywhere in it, whatever the capitals, and leave the cell empty otherwise. Your formula will be copied down to C11.
| A | B | C | |
|---|---|---|---|
| 1 | Call | Note | Flag |
| 2 | C401 | Left a voicemail | |
| 3 | C402 | Refund sent on Friday | |
| 4 | C403 | Customer wants a refund for the lid | |
| 5 | C404 | Delivery delayed again | |
| 6 | C405 | REFUND agreed by manager | |
| 7 | C406 | Changed delivery address | |
| 8 | C407 | Asked about our refund policy | |
| 9 | C408 | Wrong size sent, swap arranged | |
| 10 | C409 | Part refund of £12.50 agreed | |
| 11 | C410 | Called back, no answer |
Open this in Try a formula: the same sheet with the answer filled in, to change or share by link.
Part of Excel data cleaning practice: every lesson on the topic, with a project in Excel.
Where it works
SEARCH, FIND, ISNUMBER, ISTEXT and COUNTIF with wildcards work the same in every version of Excel, on Windows and Mac, and in Excel for the web.
Questions
How do I return a value if a cell contains certain text?
Use IF with ISNUMBER and SEARCH: =IF(ISNUMBER(SEARCH("refund",B2)),"Refund",""). SEARCH finds the word anywhere in B2 and gives its position, or an error if it isn't there. ISNUMBER turns that into TRUE or FALSE, and IF shows the first value for TRUE and the second for FALSE. Swap "Refund" for any word, number or cell you want back.
How do I check if a cell contains text in Excel?
It depends what you mean. To check for a particular word, use =ISNUMBER(SEARCH("word",B2)), which gives TRUE or FALSE. To check whether the cell holds any text at all, as opposed to a number or nothing, use =ISTEXT(B2). To check it isn't empty, whatever it holds, use =B2<>"". All three can go inside IF.
Is SEARCH or FIND better for checking text?
SEARCH, for most jobs. It ignores capitals, so it finds Refund, refund and REFUND alike, and it understands the wildcards * and ?. FIND only matches the exact capitals you type, which is useful for codes where capitals mean something, such as RF- for a refund. Both give a #VALUE! error when the text isn't there, so wrap either one in ISNUMBER.
Can I use a wildcard with IF in Excel?
Not with an equals sign: =IF(B2="*refund*",…) looks for the actual characters *refund*. Put the wildcard inside COUNTIF instead, which does understand it: =IF(COUNTIF(B2,"*refund*"),"Refund",""). COUNTIF gives 1 when the cell matches and 0 when it doesn't, and IF treats 1 as TRUE. SUMIF, MATCH, VLOOKUP and XLOOKUP understand wildcards too.