Excel:VLOOKUP 返回 true 还是 false?

发布于 2024-09-02 15:31:14 字数 134 浏览 2 评论 0原文

在 Excel 中,我们有 VLOOKUP 函数,它在表的列中查找值,如果找到某些内容,则返回该表中给定列的值。如果不存在,则会产生错误。

是否有一个函数仅根据是否在列中找到该值而返回 true 或 false?

In Excel we have the VLOOKUP function that looks for a value in a column in a table and then returns a value from a given column in that table if it finds something. If it doesn't, it produces an error.

Is there a function that just returns true or false depending on if the value was found in a column or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

椒妓 2024-09-09 15:31:14

您可以将 VLOOKUP() 包装在 IFERROR()

编辑中:在 Excel 2007 之前,使用 =IF(ISERROR()...)

You could wrap your VLOOKUP() in an IFERROR()

Edit: before Excel 2007, use =IF(ISERROR()...)

征棹 2024-09-09 15:31:14

只需使用 COUNTIF 即可!写入和计算速度比其他建议快得多。


编辑:

假设如果在 C 列中找到 B1 的值,则单元格 A1 应该为 1,否则单元格 A1 应该为 2。您会怎么做?

我想说的是,如果 B1 的值在 C 列中找到,那么 A1 将为正数,否则将为 0。这可以通过公式轻松完成:=COUNTIF($C$1:$C$15,B1),意思是:计算C1:C15范围内等于B1的单元格。

您可以将 COUNTIFVLOOKUPIF 结合使用,这比使用 2 次查找 + ISNA 快得多。 IF(COUNTIF(..)>0,LOOKUP(..),"Not found")

谷歌搜索一下就会给你带来大量的示例

Just use a COUNTIF ! Much faster to write and calculate than the other suggestions.


EDIT:

Say you cell A1 should be 1 if the value of B1 is found in column C and otherwise it should be 2. How would you do that?

I would say if the value of B1 is found in column C, then A1 will be positive, otherwise it will be 0. Thats easily done with formula: =COUNTIF($C$1:$C$15,B1), which means: count the cells in range C1:C15 which are equal to B1.

You can combine COUNTIF with VLOOKUP and IF, and that's MUCH faster than using 2 lookups + ISNA. IF(COUNTIF(..)>0,LOOKUP(..),"Not found")

A bit of Googling will bring you tons of examples.

审判长 2024-09-09 15:31:14

您仍然需要将其包装在 ISERROR 中,但可以使用 MATCH() 而不是 VLOOKUP()

返回相对位置
数组中与 a 匹配的项
按指定顺序指定值。
使用 MATCH 代替 LOOKUP 之一
当您需要该职位时发挥作用
一个范围内的项目而不是
项目本身。

这是一个完整的示例,假设您正在一系列单元格中查找单词“key”:

=IF(ISERROR(MATCH("key",A5:A16,FALSE)),"missing","found")

FALSE 是强制精确匹配所必需的,否则它将查找最接近的值。

You still have to wrap it in an ISERROR, but you could use MATCH() instead of VLOOKUP():

Returns the relative position of an
item in an array that matches a
specified value in a specified order.
Use MATCH instead of one of the LOOKUP
functions when you need the position
of an item in a range instead of the
item itself.

Here's a complete example, assuming you're looking for the word "key" in a range of cells:

=IF(ISERROR(MATCH("key",A5:A16,FALSE)),"missing","found")

The FALSE is necessary to force an exact match, otherwise it will look for the closest value.

绝影如岚 2024-09-09 15:31:14

我们一直使用

if(iserror(vlookup,"n/a",vlookup))

Excel 2007 引入的 IfError,它允许您进行 vlookup 并在出现错误时添加输出,但这对 2003 没有帮助...

We've always used an

if(iserror(vlookup,"n/a",vlookup))

Excel 2007 introduced IfError which allows you to do the vlookup and add output in case of error, but that doesn't help you with 2003...

ぽ尐不点ル 2024-09-09 15:31:14

您可以使用:

=IF(ISERROR(VLOOKUP(lookup value,table array,column no,FALSE)),"FALSE","TRUE")

You can use:

=IF(ISERROR(VLOOKUP(lookup value,table array,column no,FALSE)),"FALSE","TRUE")
离线来电— 2024-09-09 15:31:14

ISNA 是最好用的函数。我刚刚做了。我希望所有值不在数组中的单元格有条件地格式化为某种颜色。

=ISNA(VLOOKUP($A2,Sheet1!$A:$D,2,FALSE))

ISNA is the best function to use. I just did. I wanted all cells whose value was NOT in an array to conditionally format to a certain color.

=ISNA(VLOOKUP($A2,Sheet1!$A:$D,2,FALSE))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文