跳到主要内容

Excel公式:检查单元格是否包含一些文本,但不包含其他文本

若要检查单元格是否包含范围A中的某些文本,但不包含范围B中的文本,则可以使用将Excel中的COUNT,SEARCH和AND函数组合在一起的数组公式。 在这里,本教程说明了如何使用此数组公式。
doc检查是否包含某些但不包含其他1

通用公式:

=AND(COUNT(SEARCH(include,text))>0,COUNT(SEARCH(exclude,text))=0)

参数

Text: the text string you want to check.
Include: the values you want to check if argument text contains.
Exclude: the values you want to check if argument text does not contain.

返回值:

此公式返回逻辑值。 如果该单元格至少包含参数Include之一,但不包含参数Exclude之一,则它将返回TRUE,否则将返回FALSE。

这个公式如何运作

假设您要检查单元格B3是否包含范围E3:E5中的值之一,但同时不包含范围F3:F4中的任何值,请使用以下公式

=AND(COUNT(SEARCH($E$3:$E$5,B3))>0,COUNT(SEARCH($F$3:$F$4,B3))=0)

媒体 Shift + Ctrl + 输入 键检查单元格。
doc检查是否包含某些但不包含其他2

说明

部分1: ( COUNT(SEARCH($E$3:$E$5,B3))>0 检查单元格B3是否包含E3:E5范围内的值之一

搜索 函数:SEARCH函数返回文本字符串中另一个字符的第一个字符的位置,如果SEARCH函数找到匹配的文本,则返回相对位置,否则返回#VALUE! 错误。 在这里,公式 SEARCH($E$3:$E$5,B3) 将在单元格B3中搜索范围E5:E3中的每个值,并返回每个文本字符串在单元格B3中的位置。 它将返回一个数组结果,如下所示: {1;7;#VALUE!}.

COUNT个 函数:COUNT函数计算范围或数组中的项目数。 COUNT(SEARCH($E$3:$E$5,B3)) 返回2作为数组中的项目数 {1;7;#VALUE!} 是两个。

COUNT(SEARCH($E$3:$E$5,B3))>0,将COUNT函数的结果与零进行比较,只要COUNT函数的结果大于0,则结果将返回TRUE,否则将返回FALSE。 在这里,它返回TRUE。
doc检查是否包含某些但不包含其他3

部分2: COUNT(SEARCH($F$3:$F$4,B3))=0 检查单元格B3是否不包含F3:F4范围内的值之一

搜索 函数:SEARCH函数返回文本字符串中第一个字符在另一个字符内的位置,如果SEARCH函数找到匹配的文本,则返回相对位置; 如果不是,则返回#VALUE! 错误。 在这里,公式 SEARCH($F$3:$F$4,B3) 将在单元格B3中搜索范围F4:F3的每个值,并返回每个文本字符串在单元格B3中的位置。 它将返回一个数组结果,如下所示: {#VALUE!; #VALUE!;#VALUE!}.

COUNT个 函数:COUNT函数计算范围或数组中的项目数。 COUNT(SEARCH($F$3:$F$4,B3)) 返回0,因为数组中没有项目 {#VALUE!; #VALUE!;#VALUE!} .

COUNT(SEARCH($F$3:$F$4,B3))>0,将COUNT函数的结果与零进行比较,只要COUNT函数的结果等于0,它将返回TRUE,否则将返回FALSE。 在这里,它返回TRUE。
doc检查是否包含某些但不包含其他4

部分3: AND 功能

=AND(COUNT(SEARCH($E$3:$E$5,B3))>0,COUNT(SEARCH($F$3:$F$4,B3))=0)

=AND(TRUE,TRUE)

=TRUE

示例文件

doc样本点击下载示例文件


相对公式


最佳办公效率工具


Office Tab - 在 Microsoft Office(包括 Excel)中启用分页式阅读和编辑

  • 一秒钟即可在数十个打开的文档之间切换!
  • 每天为您减少数百次鼠标单击,告别鼠标手。
  • 查看和编辑多个文档时,可将您的工作效率提高50%。
  • 为 Office(包括 Excel)带来高效的选项卡,就像 Chrome、Edge 和 Firefox 一样。
Comments (3)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Is there some way to combine this tool and others to help with the following example?
In Page 1, Column A, Cell A: the sum of all values found in the range of Page 2
This comment was minimized by the moderator on the site
...Page 2, Column Range A15-A25, if the corresponding cell in Page 2, Column Range B15-B25 contains the word "Apples".
This comment was minimized by the moderator on the site
Hi, GoodEvening, I guess you want to sum values in column A if the corresponding cells in column B are the word "apples" as the screenshot below shown, if so, you can refer to below toturial, it provides the formula to solve this problem in details.https://www.extendoffice.com/excel/formulas/excel-sum-if-cell-equals-value-does-not-equal.html
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations