Excel - 递归 VLookup
最近了解了Excel的Ctrl+Shift+Enter数组公式,目前还在学习中。谈到我的问题,
SheetA:
Product Code
S1 19875
S2 19834
S1 13575
S1 35675
S2 47875
SheetB:
Code Indent
19875 40
19834 15
13575 22
35675 25
47875 20
我需要对给定产品名称的所有缩进进行求和。
例如:我需要S1的总缩进,
- 在SheetA上Vlookup,获取代码19875
- 获取40 Next Vlookup的缩进
- 在SheetB上执行vlookup,在Sheet A上
- ,获取代码13575在SheetB上使用13575进行Vlookup,获取22
- Next Vlookup 的缩进在工作表 A 上,获取代码 35675
- 使用 35675 在工作表 B 上进行 Vlookup,获取
- 40+22+25 之和的 25 缩进,返回 87
我可以通过 VBA 实现此目的,但我想知道这是否可以在使用 CSE 的 excel 函数中实现/数组公式。
编辑:
我在 Sheet2 中没有与 Sheet1 相同顺序的值。它们是完全随机的。我的 SheetB 将是随机的,如下所示:
SheetB:
Code Indent
19834 40
19875 15
47875 22
13575 25
35675 20
I recently came to know about Ctrl+Shift+Enter array formulas of Excel and currently still learning them. Coming to my problem,
SheetA:
Product Code
S1 19875
S2 19834
S1 13575
S1 35675
S2 47875
SheetB:
Code Indent
19875 40
19834 15
13575 22
35675 25
47875 20
I need to do Sum of all Indents of a given Product name.
Eg: I need S1's Total Indent,
- Vlookup on SheetA, Get the Code 19875
- Perform a vlookup on SheetB, Get the Indent of 40
- Next Vlookup on Sheet A, Get the code 13575
- Use 13575 to Vlookup on SheetB, Get Indent of 22
- Next Vlookup on Sheet A, Get the code 35675
- Use 35675 to Vlookup on SheetB, get indent of 25
- Sum of 40+22+25, Return 87
I can achieve this through VBA, but I'm wondering if this is possible within excel functions using CSE/Array formulas.
Edit:
I don't have values in Sheet2 in the same order of Sheet1.. They are completely random. My SheetB will be something randomly like following:
SheetB:
Code Indent
19834 40
19875 15
47875 22
13575 25
35675 20
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
MATCH 的第一个参数解析为
MATCH 解析为
您必须确保 SheetB 中没有零。 NOT ISNA 将这些转换为 TRUE 和 FALSE 并解析为
最终的 SUM 看起来像这样
更新
当列表处于不同顺序时,我无法找出单数组解决方案。我对 OFFSET 和 TRANSPOSE 的尝试要么给出了错误的答案,要么导致 Excel 崩溃。如果您可以使用辅助列,则可以将此公式放在第一张表的第三列中
,然后使用此数组公式对它们进行求和
The first argument of the MATCH resolves to
The MATCH resolves to
You'll have to make sure you don't have zeros in SheetB. The NOT ISNA turns those into TRUEs and FALSEs and resolves to
And the final SUM looks like this
Update
I can't figure out a single-array solution when the lists are in a different order. My attempts with OFFSET and TRANSPOSE either gave the wrong answer or crashed Excel. If you can stand using a helper column, you could put this formula in third column of your first sheet
and then use this array formula to sum them up
如果 SheetA 和 SheetB 上的代码列相同(顺序相同),则可以使用简单的 SUMIF 函数。同样,如果 INDENT 数据位于 SheetA 上,您也可以使用数据透视表来快速计算总和。
我猜你的工作簿的设计不允许这样做。在这种情况下,我没有任何简单的解决方案,但我会再看一下。
If the Code column were identical (same order) on both SheetA and SheetB, a simple SUMIF function would do. Similarly, if the INDENT data were on SheetA, you could also use a pivot table to calculate the sums quickly.
I'm guessing the design of your workbook won't allow this though. In which case, I don't have any easy solutions, but I'll give it another look.
您可以使用以下内容:
//Ola.S
表1
上校:ABC
产品代码 目标
列 C:=SUMIF($E$4:$E$8;B4;$F$4:$F$8)
表 2
科尔:EF
代码意向
表3
可旋转(列:A 和 C)
You could use the below:
//Ola.S
Table 1
Col:A B C
Product Code Intendent
Col C: =SUMIF($E$4:$E$8;B4;$F$4:$F$8)
Table 2
Col:E F
Code Intendent
Table 3
Pivottable (Col:A and C)
在表C上
如果 A1 有 S1,则在单元格 B1 中
输入数组
在哪里
Code1 = SheetA 上从 Row2 开始的代码的动态范围
Code2 = SheetB 上从 Row2 开始的代码的动态范围
On sheetC
If A1 has S1 then in Cell B1 type
Array entered
Where
Code1 = Dynamic Range for Codes on SheetA starting from Row2
Code2 = Dynamic Range for Codes on SheetB starting from Row2
不需要
TRANSPOSE
调用。尝试数组公式
假设
SheetB!A2:A6
中没有单元格,其计算结果为 FALSE。如果代码列都是数字(可能是一个有问题的假设),则无需使用数组条目即可完成此操作:假设
SheetB!A2:A6
中没有单元格计算结果为#DIV/0!
。No
TRANSPOSE
calls needed.Try the array formula
Assuming no cell in
SheetB!A2:A6
it evaluates to FALSE. If the Code columns were all numeric (probably a questionable assumption), this could be done without an array entry using:Assuming no cell in
SheetB!A2:A6
evaluates to#DIV/0!
.