简体   繁体   English

Excel:在单元格中搜索多个术语

[英]Excel: Searching for multiple terms in a cell

I use this handy equation to search for a term inside of a cell in excel.我使用这个方便的公式在 excel 中搜索单元格内的术语。

=IF(ISNUMBER(SEARCH("*Gingrich*",C1)),"1","")

This equation searches for the presence of Gingrich in C1, if it exists, it displays a 1.此等式在 C1 中搜索 Gingrich 的存在,如果存在,则显示 1。

All I'd like to do is search for more than one term at a time.我想要做的就是一次搜索多个术语。 Anyone know how to add an OR function into this so I can search for Gingrich OR Obama OR Romney etc... ?任何人都知道如何在其中添加 OR 函数,以便我可以搜索 Gingrich OR Obama OR Romney 等...?

Another way其他方式

=IF(SUMPRODUCT(--(NOT(ISERR(SEARCH({"Gingrich","Obama","Romney"},C1)))))>0,"1","")

Also, if you keep a list of values in, say A1 to A3, then you can use此外,如果您保留一个值列表,例如 A1 到 A3,那么您可以使用

=IF(SUMPRODUCT(--(NOT(ISERR(SEARCH($A$1:$A$3,C1)))))>0,"1","")

The wildcards are not necessary at all in the Search() function, since Search() returns the position of the found string. Search() 函数中根本不需要通配符,因为 Search() 返回找到的字符串的位置。

Try using COUNT function like this尝试使用这样的 COUNT 函数

=IF(COUNT(SEARCH({"Romney","Obama","Gingrich"},C1)),1,"")

Note that you don't need the wildcards (as teylyn says) and unless there's a specific reason "1" doesn't need quotes (in fact that makes it a text value)请注意,您不需要通配符(如 teylyn 所说),除非有特定原因“1”不需要引号(实际上这使它成为文本值)

This will do it for you:这将为您做到:

=IF(OR(ISNUMBER(SEARCH("Gingrich",C3)),ISNUMBER(SEARCH("Obama",C3))),"1","")

Given this function in the column to the right of the names (which are in column C), the result is:给定名称右侧列中的此函数(在 C 列中),结果为:

Romney  
Gingrich    1
Obama       1

In addition to the answer of @teylyn, I would like to add that you can put the string of multiple search terms inside a SINGLE cell (as opposed to using a different cell for each term and then using that range as argument to SEARCH ), using named ranges and the EVALUATE function as I found from this link .除了@teylyn 的答案之外,我想补充一点,您可以将多个搜索词的字符串放在单个单元格中(而不是为每个词使用不同的单元格,然后使用该范围作为SEARCH参数),使用命名范围和EVALUATE函数,正如我从这个链接中找到的那样。

For example, I put the following terms as text in a cell, $G$1 :例如,我将以下术语作为文本放入单元格$G$1

"PRB", "utilization", "alignment", "spectrum"

Then, I defined a named range named search_terms for that cell as described in the link above and shown in the figure below:然后,我为该单元格定义了一个名为search_terms的命名范围,如下图所示:

命名范围定义

In the Refers to: field I put the following:Refers to:字段中,我输入了以下内容:

=EVALUATE("{" & TDoc_List!$G$1 & "}")

The above EVALUATE expression is simple used to emulate the literal string上面的EVALUATE表达式很简单,用于模拟文字字符串

{"PRB", "utilization", "alignment", "spectrum"}

to be used as input to the SEARCH function: using a direct reference to the SINGLE cell $G$1 (augmented with the curly braces in that case) inside SEARCH does not work, hence the use of named ranges and EVALUATE .被用作输入到SEARCH功能:使用直接参考单细胞$G$1内(在这种情况下,与大括号增强) SEARCH不工作,因此,使用命名范围的和EVALUATE

The trick now consists in replacing the direct reference to $G$1 by the EVALUATE -augmented named range search_terms .现在的技巧在于用EVALUATE增强的命名范围search_terms替换对$G$1的直接引用。

公式

It really works, and shows once more how powerful Excel really is!它确实有效,并再次展示了 Excel 的强大功能!

真的行!

Hope this helps.希望这可以帮助。

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

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