[英]Check for string in text column A, return another string in column B - Excel
I am trying to lookup one of 3 strings (Blue, Red, Green) in column A. In column AI have: 我正在尝试在A列中查找3个字符串(蓝色,红色,绿色)之一。在AI列中有:
row1: "Robert has Blue shorts"
row1:“罗伯特有蓝色短裤”
row2: "Maria has a Red dress"
第2列:“玛丽亚有一件红色连衣裙”
row3: "John has a Green car"
第3列:“约翰有一辆绿色汽车”
Whenever I find one of those 3 words in column A, I want to populate column B with the found instance (Green, Red, Blue). 每当我在A列中找到这3个单词之一时,我想用找到的实例(绿色,红色,蓝色)填充B列。
There will always be one of these 3 words in column A, never more than one and the position of the words can be anywhere in the string. 在A列中,这3个单词中始终会有一个,永远不会超过一个,并且单词的位置可以在字符串中的任何位置。
I know how to put this in Python or SQL but I am struggling with Excel. 我知道如何将其放在Python或SQL中,但是我在Excel中苦苦挣扎。
Can anyone share a solution if they used this in past? 如果有人过去使用过此解决方案,谁能分享?
You can use this array formula: 您可以使用以下数组公式:
=INDEX({"Red","Blue","Green"},MATCH(TRUE,ISNUMBER(SEARCH({" Red "," Blue "," Green "}," " & A1 & " ")),0))
Being an array formula it must be confirmed with Ctrl-Shift-Enter when exiting edit mode. 作为数组公式,退出编辑模式时必须使用Ctrl-Shift-Enter确认。 If done correctly then Excel will put
{}
around the formula. 如果操作正确,则Excel会将
{}
放在公式周围。
As a note: 注意:
You can also replace the {"Red","Blue","Green"}
with a range reference. 您也可以使用范围引用替换
{"Red","Blue","Green"}
。 So if the three words were in D1:D3 the formula would be: 因此,如果三个词在D1:D3中,则公式为:
=INDEX($D$1:$D$3,MATCH(TRUE,ISNUMBER(SEARCH(" " & $D$1:$D$3 & " "," " & A1 & " ")),0))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.