在一系列单元格中查找值

时间:2017-12-06 18:27:05

标签: arrays excel search excel-formula lookup

假设我在Excel中有以下数据表

Company Amount  Text
Oracle  $3,400  330 Richard ERP
Walmart $750    348 Mary ERP
Amazon  $6,880  xxxx Loretta ERP
Rexel   $865    0000 Mike ERP
Toyota  $11,048 330 Richard ERP

我想浏览“文本”列中的每个项目,根据以下名称范围搜索项目:

Mary 
Mike 
Janine 
Susan 
Richard 
Jerry 
Loretta 

并在“Person”列中返回名称(如果找到)。例如:

Company Amount  Text    Person
Oracle  $3,400  330 Richard ERP Richard
Walmart $750    348 Mary ERP    Mary
Amazon  $6,880  xxxx Loretta ERP    Loretta
Rexel   $865    0000 Mike ERP   Mike
Toyota  $11,048 330 Richard ERP Richard

我在Excel中尝试了以下工作:

=IF(N2="","",
IF(ISNUMBER(SEARCH(Sheet2!$A$1,N2)),Sheet2!$A$1,
IF(ISNUMBER(SEARCH(Sheet2!$A$2,N2)),Sheet2!$A$2,
IF(ISNUMBER(SEARCH(Sheet2!$A$3,N2)),Sheet2!$A$3,
....

其中$ A $ 1:$ A $ 133是我的范围,N2是“文本”列值;但是,这是很多嵌套代码,显然Excel对可以拥有的嵌套IF语句的数量有限制。

是否有更简单的解决方案(数组?VBA?)

谢谢!

1 个答案:

答案 0 :(得分:1)

使用以下公式:

=IFERROR(INDEX(Sheet2!A:A,AGGREGATE(15,6,ROW(Sheet2!$A$1:INDEX(Sheet2!A:A,MATCH("zzz",Sheet2!A:A)))/(ISNUMBER(SEARCH(Sheet2!$A$1:INDEX(Sheet2!A:A,MATCH("zzz",Sheet2!A:A)),N2))),1)),"")

enter image description here