How can I assign a value to cells if it's neighbour contains a specific string?
For example, fields in column A:
dog11
cat22
cow11
chick11
duck22
cat11
horse22
cat33
The syntax in column B would be:
=IF(SEARCH("cat",A1),"cat",IF(SEARCH("22",A1),"22","none"))
It always picks up the first TRUE cell, but drops when the value is not true.
SEARCH
does not return0
if there is no match, it returns#VALUE!
. So you have to wrap calls toSEARCH
withIFERROR
.For example...
or
Here,
IFERROR
returns the value fromSEARCH
when it works; the given value of0
otherwise.You can use
OR()
to group expressions (as well asAND()
):So if you wanted to test for "cat" and "22":