vba 如何在另一个工作表中找到匹配的数据并获取单元格值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14508594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I find matching data in another worksheet and get a cell value?
提问by Jeff Brady
I have an Excel workbook with 2 worksheets. Let's call them "Item List" and "Item Master".
我有一个包含 2 个工作表的 Excel 工作簿。我们称它们为“物品清单”和“物品大师”。
In "Item List" I have 2 columns, B ("Code") and C ("Subcode"). It looks like this:
在“项目列表”中,我有 2 列,B(“代码”)和 C(“子代码”)。它看起来像这样:
A B C
----------------
100 AR
110 AR
120 NU
130 AR
In "Item Master" I have similar columns, K ("Code") and L ("Subcode"). It looks like this:
在“Item Master”中,我有类似的列,K(“代码”)和 L(“子代码”)。它看起来像这样:
E K L
----------------
xx 100 AR
xx 100 AR
xy 120 NU
xc 120 AR
xz 130 AR
In "Item List", I need to have column C show the value of "Item Master" column E, IF the values of B and C match the values of K and L.
在“项目列表”中,我需要让 C 列显示“项目主”列 E 的值,如果 B 和 C 的值与 K 和 L 的值匹配。
So if (Item List)A AND (Item List)B match (Item Master)K AND (Item Master)L, then (Item List)C = (Item Master)E
所以如果 (Item List)A AND (Item List)B 匹配 (Item Master)K AND (Item Master)L,那么 (Item List)C = (Item Master)E
If there are multiple matches, the search can stop after the first match and get the value of column E since it will be the same for all matches.
如果有多个匹配项,搜索可以在第一个匹配项后停止并获取 E 列的值,因为所有匹配项的值都相同。
How can this be done?
如何才能做到这一点?
回答by Scott Holtzman
In the Item Master
sheet, create the following formula in Column M =(K2&L2)
, then drag it down the rowset.
在工作Item Master
表中,在 M 列中创建以下公式=(K2&L2)
,然后将其向下拖动到行集。
In column C of the Item List
sheet write this formula.
在Item List
表格的C 列中写下这个公式。
=Offset(`Item Master`!$E,match($A2&$B2,'Item Master`!$M:$M,0)-1,0)
then fill down the row set.
然后填写行集。
回答by Siddharth Rout
You can also use This array formula. You have to use CTL+ SHIFT+ ENTERafter you enter the formula. This will negate the use of using a helper column
您也可以使用此数组公式。你必须使用CTL+ SHIFT+ENTER您输入公式后。这将否定使用辅助列的使用
=INDEX('Item Master'!E:E,MATCH(1,('Item Master'!L:L=B1)*('Item Master'!K:K=A1),0))
=INDEX('Item Master'!E:E,MATCH(1,('Item Master'!L:L=B1)*('Item Master'!K:K=A1),0))
The above formula goes in C1
of Item List
You can then copy it down...
上面的公式进去了C1
, Item List
然后你可以把它复制下来......
SCREENSHOT
截屏