简体   繁体   English

检查一列的任何值是否包含另一列的任何值

[英]Check if any values of one column contains any values from another column

So I have a formula I've been using to see if any of the cells in one column matches any of the cells in another group of values (in a different sheet called companies): 因此,我有一个公式一直在使用,以查看一列中的任何单元格是否与另一组值中的任何单元格相匹配(在另一个称为公司的工作表中):

 =IF(ISERROR(VLOOKUP(K1,companies!A:A,1,FALSE)),"Keep","Delete")

Now I'm trying to do the exact same thing, only now I want to see if any of the cells CONTAIN any substring of the cells (companies!A:A) rather than MATCH. 现在,我尝试做完全相同的事情,只是现在,我想查看是否有任何单元格包含单元格的任何子字符串(companies!A:A),而不是匹配。 Not sure how to do this though. 不确定如何执行此操作。

=IF(ISERROR(VLOOKUP(CONCATENATE("*",K1,"*"),companies!A:A,1,FALSE)),"Keep","Delete")

Just change your K1 reference to CONCATENATE("*",K1,"*") which will make the vlookup wildcard based. 只需将您的K1引用更改为CONCATENATE("*",K1,"*") ,即可基于vlookup通配符。

Here's an image showing this working, though modified to all be in one sheet. 这是一张显示此工作方式的图像,尽管将其修改为一张纸。 You can see one, four and five get delete because they're contained in the list, but not EXACTLY in the list. 您会看到一个,四个和五个被删除,因为它们包含在列表中,但不完全包含在列表中。

EDIT So after some discussion in the comments, it turns out the above is a misunderstanding of the need. 编辑因此,在评论中进行了一些讨论之后,发现以上内容是对需求的一种误解。 The question actually wants to be able to see if a certain value contains ANY of the strings in another column, which is a bit more difficult of a problem - but this was bugging me so I worked on it and I think I've got something that works. 这个问题实际上是想知道某个值是否包含另一列中的任何字符串,这在问题上要困难得多-但这使我感到烦恼,所以我进行了研究,我认为我有所收获这样可行。

Here's the formula: 公式如下:

=IF(OR(ISNUMBER(SEARCH("*"&$H$2:$H$14&"*",I2))),"Delete","Keep")

This has to be entered using CTRL-SHIFT-ENTER to make it an array function to work 必须使用CTRL-SHIFT-ENTER输入它,以使其成为数组函数才能工作

The reference column must also be explicitly defined (ie H#:H#,not H:H) or else everything will return true, as the empty cells below your data will match anything. 还必须明确定义引用列(即H#:H#,而不是H:H),否则所有内容将返回true,因为数据下方的空白单元格将匹配任何内容。

That all being said, you'll know its an array function because it will have brackets around the formula in the formula bar as you can see below. 话虽如此,您将知道它是一个数组函数,因为它将在公式栏中的公式两边带有方括号,如下所示。

数组公式

I strongly recommend going through the "Evaluate Formula" tool to see how this works yourself, but I'll break it down best I can below, using an example of a matching row since it's more obvious. 我强烈建议您浏览“评估公式”工具,以了解自己的工作方式,但是我将在下面以匹配行的示例为依据,对其进行详细说明,因为它更加明显。

First, excel evaluates your reference and concatenation into an array of the cell values and replaced your reference for the string to be searched, so we get something like: 首先,excel将您的引用和连接评估为单元格值的数组,并将您的引用替换为要搜索的字符串,因此我们得到如下信息:

=IF(OR(ISNUMBER(SEARCH({"*john*";"*jack*";"*fake*";"*bill*";"*bob*";"*test*";"*blah*";"*hey*";"*words*";"*ten*";"*eleven*";"*jim*";"*susie*"},"fake@example.org"))),"Delete","Keep")

Excel then performs the search for each of those terms against the string you want to search, and this returns an array of the results of that. 然后,Excel将针对您要搜索的字符串对每个术语进行搜索,这将返回结果的数组。 Note search returns "#VALUE" when there's no match. 没有匹配项时,注释搜索将返回“ #VALUE”。

=IF(OR(ISNUMBER({#VALUE;#VALUE;1;#VALUE;#VALUE;#VALUE;#VALUE;#VALUE;#VALUE;#VALUE;#VALUE;#VALUE;#VALUE})),"Delete","Keep")

Excel then does IsNumber against this array, and again, stores the True/False results in the array. 然后,Excel对这个数组执行IsNumber,然后再次将True / False结果存储在数组中。

=IF(OR({FALSE;FALSE;TRUE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE;FALSE}),"Delete","Keep")

We then added the OR, which will evaluate against the array and return True if any of the results are True, and then the If is evaluated. 然后,我们添加了OR,它将对数组求值,如果任何结果为True,则返回True,然后对If求值。

Seems to work, though performance may suck against a large dataset. 似乎可以正常工作,尽管性能可能会影响大型数据集。 This kind of stuff would be better suited for some sort of SQL tool. 这种东西将更适合某种SQL工具。

暂无
暂无

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

相关问题 有没有办法将列值从一个工作表复制到另一个工作表作为基于第一个分组的行 - is there any way to copy column values from one sheet to another sheet as row based on sheet one grouping 将值从一列移动到另一列 - Move values from one column to another column 如果列 H 包含以下任何值,则删除行 - VBA - Delete row if Column H contains any of the following values - VBA 用于检查一列中的值组合以与另一列中的组合匹配的公式 - Formula to check combinations of values in one column to match with combinations in another column Excel 如果一列包含唯一值,而另一列包含一个真值,则返回这些唯一值的所有真值 - Excel If one column contains unique values, and another column contains one true value, return all true values for those unique values 如何检查从一个列到另一个列的每个单元格中每个单元格的值 - How to check values in each cell from one column to each cell in another column Excel-将值从一列复制到另一列 - Excel - copy values from one column to another Excel VBA-如果列B包含任何值,则使用值更新列A。 如果列B不包含任何值,则不要运行宏 - Excel VBA - Update column A with a value if column B contains any value. If column B contains no values then do not run the macro 我试图找到一个公式,如果它包含位于另一列中的任何单词,可以突出显示一列中的单元格 - I am trying to find a formula that can highlight a cell in one column if it contains any of the words located in another column Excel中的列值可将值(如果有的话)放置在第二行的另一列中,用于合并邮件 - column values in excel to place the values (if any) in another column across the second row for a mailmerge word
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM