如果单元格包含一个字符串 [英] IF a cell contains a string
问题描述
如果它的邻居包含特定的字符串,我如何为单元格赋值?
例如,列A中的字段:
dog11
cat22
cow11
chick11
duck22
cat11
horse22
cat33
列B中的语法将是:
($$)= IF(SEARCH(cat,A1),cat,IF(SEARCH(22,A1),22,none))
它总是拾取第一个TRUE单元格,但是当该值不为真时,它将丢弃。
搜索
不返回 0
如果没有匹配,它返回 #VALUE!
。因此,您必须使用 IFERROR
将呼叫转到 SEARCH
。
例如...
= IF(IFERROR(SEARCH(cat,A1),0),cat none)
或
= IF(IFERROR(SEARCH( 猫,A1),0), 猫,IF(IFERROR(SEARCH( 22,A1),0), 22, 无))
这里, IFERROR
从 SEARCH
当它工作;给定值 0
否则。
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 return 0
if there is no match, it returns #VALUE!
. So you have to wrap calls to SEARCH
with IFERROR
.
For example...
=IF(IFERROR(SEARCH("cat", A1), 0), "cat", "none")
or
=IF(IFERROR(SEARCH("cat",A1),0),"cat",IF(IFERROR(SEARCH("22",A1),0),"22","none"))
Here, IFERROR
returns the value from SEARCH
when it works; the given value of 0
otherwise.
这篇关于如果单元格包含一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!