简体   繁体   English

Excel公式来检查一个单元格中的逗号分隔列表中的项是否存在于另一单元格中的逗号分隔列表中?

[英]Excel formula to check if items from a comma separated list in one cell exist in a comma separated list in another cell?

I have a spreadsheet where every row has two columns, each containing a comma separated list of words or phrases. 我有一个电子表格,其中每一行都有两列,每列包含一个用逗号分隔的单词或短语列表。

Column 1                        | Column 2
---------------------------------------------------------
Orange, Pear, Sugar apple, Kiwi | Orange, Sugar apple
Banana, Watermelon, Pomegranate | Strawberry, Banana

I'm trying to create a formula that checks if the items listed in Column 2 are a subset of the items listed in Column 1 and outputs true or false . 我正在尝试创建一个公式,以检查第2列中列出的项目是否是第1列中列出的项目的子集,并输出truefalse

In the above example the output should be true for Row 1 and false for Row 2. 在上面的示例中,第1行的输出应为true ,第2行的输出应为false

The solutions I tried using the search and find functions only work if the items in Column 2 are listed in the same sequence, ie if Column 2 is a substring of Column 1. 我使用searchfind功能尝试的解决方案仅在按相同顺序列出第2列中的项目时才有效,即,如果第2列是第1列的子字符串。

Use this array formula: 使用此数组公式:

=AND(ISNUMBER(SEARCH(", " & TRIM(MID(SUBSTITUTE(B1,",",REPT(" ",99)),(ROW($XFD$1:INDEX(XFD:XFD,LEN(B1)-LEN(SUBSTITUTE(B1,",",""))+1))-1)*99+1,99)) & ",",", "&A1&",")))

Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode 作为数组公式,退出编辑模式时必须使用Ctrl-Shift-Enter而不是Enter进行确认

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM