Excel:VLOOKUP 返回 true 还是 false?
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以将 VLOOKUP() 包装在 IFERROR()
编辑中:在 Excel 2007 之前,使用
=IF(ISERROR()...)
You could wrap your VLOOKUP() in an IFERROR()
Edit: before Excel 2007, use
=IF(ISERROR()...)
只需使用 COUNTIF 即可!写入和计算速度比其他建议快得多。
编辑:
我想说的是,如果 B1 的值在 C 列中找到,那么 A1 将为正数,否则将为 0。这可以通过公式轻松完成:
=COUNTIF($C$1:$C$15,B1),意思是:计算
C1:C15
范围内等于B1
的单元格。您可以将
COUNTIF
与VLOOKUP
和IF
结合使用,这比使用 2 次查找 + ISNA 快得多。IF(COUNTIF(..)>0,LOOKUP(..),"Not found")
谷歌搜索一下就会给你带来大量的示例。
Just use a COUNTIF ! Much faster to write and calculate than the other suggestions.
EDIT:
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 rangeC1:C15
which are equal toB1
.You can combine
COUNTIF
withVLOOKUP
andIF
, 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.
您仍然需要将其包装在 ISERROR 中,但可以使用
MATCH()
而不是VLOOKUP()
:这是一个完整的示例,假设您正在一系列单元格中查找单词“key”:
FALSE
是强制精确匹配所必需的,否则它将查找最接近的值。You still have to wrap it in an ISERROR, but you could use
MATCH()
instead ofVLOOKUP()
:Here's a complete example, assuming you're looking for the word "key" in a range of cells:
The
FALSE
is necessary to force an exact match, otherwise it will look for the closest value.我们一直使用
Excel 2007 引入的 IfError,它允许您进行 vlookup 并在出现错误时添加输出,但这对 2003 没有帮助...
We've always used an
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...
您可以使用:
You can use:
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))