将一个列中的值与另一个列中的值进行比较。

huangapple go评论58阅读模式
英文:

Compare values in one column with another column

问题

A2包含cotton,leather

B2包含Leather,wool,cotton

我需要查看A2中的所有值是否在B2中存在,不考虑大小写顺序,也不考虑B2中是否有额外的值。

所以我需要一个公式,对于上面的示例,在C2中表示存在。

=IF(AND(ISNUMBER(SEARCH(","&LOWER(TRIM(A2))&",", ","&LOWER(TRIM(B2))&","))), "present", "not present")

这个公式可以按顺序工作。但对于上面的示例,它会显示“not present”。

其他示例如下:

Column A Column B Result
cotton,leather Leather,wool,cotton Present
red red,blue Present
cotton candy,pink pink,red,cotton candy Present
blue red,yellow Not Present
Infant,toddler Baby,Toddler Not Present
Adult,Baby,Taller,Kidder Adult,Kid Not Present
Steel Alloy Steel,Wood Not Present
英文:

A2 has cotton,leather

B2 has Leather,wool,cotton

I need to see if all values in A2 is present in B2 irrespective of case or order or any extra values in B2.

So i need a formula which says present in C2 for the above example.

=IF(AND(ISNUMBER(SEARCH(","&LOWER(TRIM(A2))&",", ","&LOWER(TRIM(B2))&","))), "present", "not present")

this formula works if it's in order. but for the above example it says not present.

Few other examples are:

Column A Column B Result
cotton,leather Leather,wool,cotton Present
red red,blue Present
cotton candy,pink pink,red,cotton candy Present
blue red,yellow Not Present
Infant,toddler Baby,Toddler Not Present
Adult,Baby,Taller,Kidder Adult,Kid Not Present
Steel Alloy Steel,Wood Not Present

答案1

得分: 2

使用 <kbd>TEXTSPLIT()</kbd><kbd>SEARCH()</kbd>


• 在单元格 C2 中使用的公式

=IF(
    OR(
    ISERROR(
    SEARCH(
    "&amp;TEXTSPLIT(A2,&quot;,&quot;)&amp;","&quot;,&quot;&amp;B2&amp;&quot;,&quot;))),
    "Not ","")
    &amp;"Present"

或者,


• 在单元格 C2 中使用的公式

=IF(
    AND(
    ISNUMBER(
    SEARCH(
    "&amp;TEXTSPLIT(A2,&quot;,&quot;)&amp;","&quot;,&quot;&amp;B2&amp;&quot;,&quot;))),
    "","Not ")
    &amp;"Present"

尝试使用 <kbd>FILTERXML()</kbd>


• 在单元格 C2 中使用的公式

=IF(
    AND(
    ISNUMBER(
    SEARCH(
    "&amp;FILTERXML(&quot;&lt;m&gt;&lt;b&gt;&quot;&amp;SUBSTITUTE(A2,&quot;,&quot;,&quot;&lt;/b&gt;&lt;b&gt;&quot;)&amp;&quot;&lt;/b&gt;&lt;/m&gt;&quot;,&quot;//b&quot;)&amp;","&quot;,&quot;&amp;B2&amp;&quot;,&quot;))),
    "Present","Not Present"
    )

注意: 根据您的Excel版本,在退出编辑模式时,需要按下 <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>ENTER</kbd>


要了解更多关于 <kbd>FILTERXML()</kbd> 的信息,强烈推荐由 JvdV 先生 专门发布的帖子:

Excel - 使用 FILTERXML 从字符串中提取子串


英文:

Using <kbd>TEXTSPLIT()</kbd> & <kbd>SEARCH()</kbd>

将一个列中的值与另一个列中的值进行比较。


• Formula used in cell C2

=IF(
    OR(
    ISERROR(
    SEARCH(
    &quot;,&quot;&amp;TEXTSPLIT(A2,&quot;,&quot;)&amp;&quot;,&quot;,&quot;,&quot;&amp;B2&amp;&quot;,&quot;))),
    &quot;Not &quot;,&quot;&quot;)
    &amp;&quot;Present&quot;

Or,

将一个列中的值与另一个列中的值进行比较。


• Formula used in cell C2

=IF(
    AND(
    ISNUMBER(
    SEARCH(
    &quot;,&quot;&amp;TEXTSPLIT(A2,&quot;,&quot;)&amp;&quot;,&quot;,&quot;,&quot;&amp;B2&amp;&quot;,&quot;))),
    &quot;&quot;,&quot;Not &quot;)
    &amp;&quot;Present&quot;

Try using <kbd>FILTERXML()</kbd>


将一个列中的值与另一个列中的值进行比较。


• Formula used in cell C2

=IF(
    AND(
    ISNUMBER(
    SEARCH(
    &quot;,&quot;&amp;FILTERXML(&quot;&lt;m&gt;&lt;b&gt;&quot;&amp;SUBSTITUTE(A2,&quot;,&quot;,&quot;&lt;/b&gt;&lt;b&gt;&quot;)&amp;&quot;&lt;/b&gt;&lt;/m&gt;&quot;,&quot;//b&quot;)&amp;&quot;,&quot;,&quot;,&quot;&amp;B2&amp;&quot;,&quot;))),
    &quot;Present&quot;,&quot;Not Present&quot;
    )

Note: Based on your Excel Version one needs to hit <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>ENTER</kbd> while exiting the edit mode.


To learn more on <kbd>FILTERXML()</kbd> highlighly recommended post exclusively by JvdV Sir:

Excel - Extract substring(s) from string using FILTERXML


huangapple
  • 本文由 发表于 2023年6月29日 15:28:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76578885.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定