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
- Login or register to post comments
- 14309 reads
Another Formula
Hi Nick,
Nice approach there
One could also use =IFERROR(SEARCH($A$3,C3)>0,FALSE) and apply this to the other cells in the range