Is there an in-built function to check if a cell contains a given character/substring?
It would mean you can apply textual functions like Left
/Right
/Mid
on a conditional basis without throwing errors when delimiting characters are absent.
Is there an in-built function to check if a cell contains a given character/substring?
It would mean you can apply textual functions like Left
/Right
/Mid
on a conditional basis without throwing errors when delimiting characters are absent.
This formula seems more intuitive to me:
this returns TRUE if "SomeText" is contained within A1.
The IsNumber/Search and IsError/Find formulas mentioned in the other answers certainly do work, but I always find myself needing to look at the help or experimenting in Excel too often with those ones.
This is an old question but a solution for those using Excel 2016 or newer is you can remove the need for nested if structures by using the new
IFS( condition1, return1 [,condition2, return2] ...)
conditional.I have formatted it to make it visually clearer on how to use it for the case of this question:
Since
SEARCH
returns an error if a string is not found I wrapped it with anISERROR(...)=FALSE
to check for truth and then return the value wanted. It would be great ifSEARCH
returned 0 instead of an error for readability, but thats just how it works unfortunately.Another note of importance is that
IFS
will return the match that it finds first and thus ordering is important. For example if my strings wereSurf, Surfing, Surfs
asString1,String2,String3
above and my cells string wasSurfing
it would match on the first term instead of the second because of the substring beingSurf
. Thus common denominators need to be last in the list. MyIFS
would need to be orderedSurfing, Surfs, Surf
to work correctly (swappingSurfing
andSurfs
would also work in this simple example), butSurf
would need to be last.