简体   繁体   English

在 vlookup 结果中删除#N/A

[英]Remove #N/A in vlookup result

How do I modify this function so that the result will merely be a blank cell rather than having #N/A show up if B2 has nothing in that cell?我该如何修改这个 function 以便结果只是一个空白单元格而不是在 B2 单元格中没有任何内容时显示#N/A?

I think I might need something like an ISERROR check but I don't 100% know what I'm doing.我可能需要类似 ISERROR 检查的东西,但我不是 100% 知道我在做什么。

=VLOOKUP(B2,Index!A1:B12,2,FALSE)

Thanks!谢谢!

If you only want to return a blank when B2 is blank you can use an additional IF function for that scenario specifically, ie 如果您只想在B2为空时返回空白,则可以特别为该场景使用额外的IF函数,即

=IF(B2="","",VLOOKUP(B2,Index!A1:B12,2,FALSE))

or to return a blank with any error from the VLOOKUP (eg including if B2 is populated but that value isn't found by the VLOOKUP) you can use IFERROR function if you have Excel 2007 or later, ie 或者返回带有VLOOKUP 错误的空白(例如,如果填充了B2,但VLOOKUP未找到该值),如果您使用的是Excel 2007或更高版本,则可以使用IFERROR函数,即

=IFERROR(VLOOKUP(B2,Index!A1:B12,2,FALSE),"")

in earlier versions you need to repeat the VLOOKUP, eg 在早期版本中,您需要重复VLOOKUP,例如

=IF(ISNA(VLOOKUP(B2,Index!A1:B12,2,FALSE)),"",VLOOKUP(B2,Index!A1:B12,2,FALSE))

if you are looking to change the colour of the cell in case of vlookup error then go for conditional formatting . 如果您想在vlookup错误的情况下更改单元格的颜色,请转到条件格式。 To do this go the "CONDITIONAL FORMATTING" > "NEW RULE". 要做到这一点,请转到“有条件的格式”>“新规则”。 In this choose the "Select the rule type" = "Format only cells that contains" . 在此选择“选择规则类型”=“仅格式化包含的单元格”。 After this the window below changes , in which choose "Error" in the first drop-down .After this proceed accordingly. 在此之后,下面的窗口发生变化,在第一个下拉列表中选择“错误”。之后相应地继续。

New Answer 9/28/2022新答案 2022 年 9 月 28 日

Here a new approach considering the new Excel function: XLOOKUP这里考虑新的 Excel function 的新方法: XLOOKUP

=XLOOKUP(D2,$A$2:$A$5,$B$2:$B$5,"Not Found",0)

The third argument indicates the value to use in case of not found, you can replace it with "" in case you want to leave the cell empty.第三个参数表示在未找到的情况下使用的值,如果您想将单元格留空,可以将其替换为""

示例 excel 文件

Check the following additional resources for more information about this new function:查看以下附加资源,了解有关此新 function 的更多信息:

  1. XLOOKUP vs VLOOKUP: Which Excel Function Is Better? XLOOKUP 与 VLOOKUP:哪个 Excel Function 更好? . . It is more flexible than VLOOKUP , you can specify lookup_array and lookup_result ranges.它比VLOOKUP更灵活,您可以指定lookup_arraylookup_result范围。
  2. Performance of XLOOKUP: How fast is the new XLOOKUP vs. VLOOKUP? XLOOKUP 的性能:新的 XLOOKUP 与 VLOOKUP 相比有多快? :it seems some concern about XLOOKUP performance. :似乎对XLOOKUP性能有些担忧。 Something to watch.值得一看的东西。

To avoid errors in any excel function, use the Error Handling functions that start with IS* in Excel. 要避免任何Excel函数中的错误,请使用以Excel中的IS *开头的错误处理函数。 Embed your function with these error handing functions and avoid the undesirable text in your results. 使用这些错误处理功能嵌入您的函数,并避免结果中出现不需要的文本。 More info in OfficeTricks Page OfficeTricks页面中的更多信息

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

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