简体   繁体   English

检查文本列A中的字符串,并返回列B中的另一个字符串-Excel

[英]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.

相关问题 Excel:如果在另一列中找到匹配项,则删除文本字符串的一部分 - Excel: Remove part of text string if a match is found in another column 在Excel的A列中从B列中找到字符串的共同点 - Find Common of string from column B in Column A in excel Excel 函数 - 如果在 B 列中找到 A 列中的字符串,则 - Excel Function - If string from column A is found in Column B Then 自动将B列上的链接添加到Excel中A列中的字符串 - Automatically adding a link on column B to a string in column A in Excel EXCEL:检查是否在另一列中找到单元格文本 - EXCEL: Check if cell text is found in another column Excel-检查值是否存在于另一个工作表的列中并返回相邻列 - Excel - Check if value exists in a column in another worksheet and return adjacent column 在B列中找到文本字符串时,给A列 - Give column A when you find text string in column B Excel:如何在包含字符串的列中查找单元格并在另一列行中返回单元格的值? - Excel: How to find cell in a column that contains a string and return value of a cell in another column of row? 检查 B 列是否包含 A 列中存在的特定字符串,然后将其从 B 列中的单元格中删除 - Check if column B contains a specific string that exists in column A and then remove it from the cell in column B 从Excel中的另一个A查找B列中的一部分文本 - To find a part of text in column B from another A in excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM