58. Excel Tips - Does a cell contain a string?

How do you find out whether a cell contains a certain string ?
- In VBA, it's easy.. use the INSTR function, and test whether this is greater than 0.
In Excel, you need to use both the LEN and the SUBSTITUTE functions.
=LEN(SUBSTITUTE(StringCell,StringToLookForCell,"",1))<>LEN(StringToLookForCell)
Let's see how this works.
- In plain English, all this is saying is:
- If I replace a string in another string with nothing.. is the length of the new string the same.
- If YES, then nothing was replaced, and the first string is not within the second.
- If NO, then something was replaced, and the first string IS within the second.
Here's our data:
Download sheet to practise finding out whether a cell contains a string
Training Video on whether cell contains a string:
»
- Nick's blog
- Add new comment
- 1720 reads

Recent comments
12 hours 25 min ago
19 hours 42 min ago
22 hours 35 min ago
22 hours 40 min ago
1 day 13 hours ago
1 day 13 hours ago
1 day 23 hours ago
2 days 15 hours ago
3 days 15 hours ago
3 days 16 hours ago