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
/R
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:
=IFS(
ISERROR(SEARCH("String1",A1))=FALSE,"Something1",
ISERROR(SEARCH("String2",A1))=FALSE,"Something2",
ISERROR(SEARCH("String3",A1))=FALSE,"Something3"
)
Since SEARCH
returns an error if a string is not found I wrapped it with an ISERROR(...)=FALSE
to check for truth and then return the value wanted. It would be great if SEARCH
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 were Surf, Surfing, Surfs
as String1,String2,String3
above and my cells string was Surfing
it would match on the first term instead of the second because of the substring being Surf
. Thus common denominators need to be last in the list. My IFS
would need to be ordered Surfing, Surfs, Surf
to work correctly (swapping Surfing
and Surfs
would also work in this simple example), but Surf
would need to be last.
Check out the FIND()
function in Excel.
Syntax:
FIND( substring, string, [start_position])
Returns #VALUE!
if it doesn't find the substring.
I like Rink.Attendant.6 answer. I actually want to check for multiple strings and did it this way:
First the situation: Names that can be home builders or community names and I need to bucket the builders as one group. To do this I am looking for the word "builder" or "construction", etc. So -
=IF(OR(COUNTIF(A1,"*builder*"),COUNTIF(A1,"*builder*")),"Builder","Community")