[英]Excel VLOOKUP or INDEX MATCH
Lets say I have 3 columns of data 假设我有3列数据
AMOUNT(A) AMOUNT(B) INVOICE(C)
55 49 4541
47 47 1515
42 47 4478
86 12 9993
12 100 1224
5 44 1452
100 4287
99 4444
What I need to check to see if the value in column A matches a value in column B. If there is a match, it will return the value from column C in column D. Now this is easy with a VLOOKUP however I am dealing with 700+ lines and there are multiple amounts that match. 我需要检查以查看列A中的值是否与列B中的值匹配。如果匹配,它将从列D中的列C返回值。现在这很容易使用VLOOKUP然而我正在处理700多行,有多个匹配的金额。 INDEX(MATCH) could work but it only returns one value.
INDEX(MATCH)可以工作但它只返回一个值。 Is this a VB only problem?
这是VB唯一的问题吗?
IE Value 47 exists in column B twice so therefore column D would return both invoice numbers (1515 - 4478) IE值47存在于B列两次,因此D列将返回两个发票号(1515 - 4478)
In VBA, the problem would be trivial as you have already correctly described the logic with the problem statement itself. 在VBA中,问题将是微不足道的,因为您已经使用问题语句本身正确描述了逻辑。
Using Excel functionality only, without VBA is the interesting problem. 仅使用Excel功能,没有VBA是一个有趣的问题。 You need to do the following steps to achieve an output that looks like this...
您需要执行以下步骤才能获得如下所示的输出...
The steps are as follows: 步骤如下:
(B)
and (C)
with Rows Fields as (B)
and (C)
and the minimum of AMOUNT(B)
as the Value field. (B)
和(C)
一个数据透视表,其中行字段为(B)
和(C)
,最小值为AMOUNT(B)
为值字段。 (See Figure below) (Q)
which is simply equal to everything in column (P)
(Q)
,它与列(P)
所有内容完全相同 Contd ... : In column (R)
(which unfortunately happens to be in the sheet's column Q, sorry for the confusion there), as shown, for cell Q20
for eg put in the formula Contd ...:在列
(R)
(遗憾的是恰好位于工作表的列Q中,对不起那里的混淆),如图所示,对于单元格Q20
,例如放入公式中
=IF(P21=P20,Q21&","&M20,M20)
That will result in the creation of something like the table below: 这将导致创建类似下表的内容:
Table: 表:
(P) (Q)
12 9993
44 1452
47 4478,1515
47 4478
49 4541
99 4444
100 4287,1224
100 4287
Now the hard work is done. 现在努力工作已经完成。 All you need to do is to lookup using
VLOOKUP
key-value pairs from this helper table (P)(Q)
- It will be very fast because the pivot table always keeps it sorted and hence an exact LOOKUP
is not necessary. 您需要做的就是使用此辅助表
(P)(Q)
VLOOKUP
键值对进行查找 - 它将非常快,因为数据透视表始终对其进行排序,因此不需要精确的LOOKUP
。 - Screenshots are shown below for the Pivot table as well as for the final VLOOKUP
formula - 下面显示了数据透视表以及最终
VLOOKUP
公式的屏幕截图
Pivot Table and Helper Table: 数据透视表和助手表:
Final Formula: 最终公式:
so I'm using the Countif to see if there are dups based on column A. In the D column type, =IF(COUNTIF($A$2:$A$9,B2)>0,C2,"")
所以我使用Countif来查看是否有基于A列的重复。在D列类型中,
=IF(COUNTIF($A$2:$A$9,B2)>0,C2,"")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.