简体   繁体   English

Excel使用条件数组跨多个工作表求和

[英]Excel sum across multiple sheets with criteria array

I have a workbook with several sheets, each containing a large amount of data formatted identically. 我有一本包含几张纸的工作簿,每张纸包含大量格式相同的数据。 What I'd like to do is enter a formula on a summary sheet that sums data from across the data sheets, selecting the data to sum based on an array of criteria. 我想做的是在摘要表上输入一个公式,该公式对数据表中的数据进行求和,然后根据一组条件选择要求和的数据。

The list of sheets is named 'AdHoc_Sheets' and the list of criteria is named 'Uncontrollable_Compensation'. 工作表列表名为“ AdHoc_Sheets”,条件列表名为“ Uncontrollable_Compensation”。

First attempt: 第一次尝试:

=SUMPRODUCT(SUMIF(INDIRECT("'"&AdHoc_Sheets&"'!"&"C:C"),A40,INDIRECT("'"&AdHoc_Sheets&"'!"&"E:E")))

This works well when only a single criteria (in this case 'A40') is needed. 当仅需要一个标准(在这种情况下为“ A40”)时,此方法效果很好。 The challenge I'm finding is changing that to be an array of criteria. 我发现的挑战是将其更改为一系列标准。

Second attempt: 第二次尝试:

 ={SUMPRODUCT(SUM(IF(ISERROR(MATCH(INDIRECT("'"&AdHoc_Sheets&"'!"&"C:C"),TRANSPOSE(Uncontrollable_Compensation),0)),0,INDIRECT("'"&AdHoc_Sheets&"'!"&"E:E"))))}

Which returns a zero when it's not CSE'd and an #N/A error when it is CSE'd. 如果不使用CSE,则返回零;如果不使用CSE,则返回#N / A错误。 Something about the dynamics of juggling the arrays is messing me up, and I can't quite tell if I need to turn to MMULT or some other method. 关于处理数组的动态问题使我感到困惑,我无法确定是否需要使用MMULT或其他方法。 Thanks in advance. 提前致谢。

Assuming that the entries in column C are text, not numeric, array formula** : 假设C列中的条目是文本而不是数字, 则为数组公式**

=SUM(IF(ISNUMBER(MATCH(T(OFFSET(INDIRECT("'"&AdHoc_Sheets&"'!"&"C1"),TRANSPOSE(ROW(C1:C100)-MIN(ROW(C1:C100))),0)),Uncontrollable_Compensation,0)),N(OFFSET(INDIRECT("'"&AdHoc_Sheets&"'!"&"E1"),TRANSPOSE(ROW(C1:C100)-MIN(ROW(C1:C100))),0))))`

With such a construction you cannot 'get away' with arbitrarily referencing entire columns without detriment to performance. 通过这种结构,您不能在不影响性能的情况下随意引用整个列。 Hence my choice of range from row 1 to row 100, which obviously you can change, though be sure to keep it as small as possible. 因此,我选择从第1行到第100行的范围,尽管一定要保持尽可能小,但显然可以更改。

Regards 问候

**Array formulas are not entered in the same way as 'standard' formulas. **数组公式的输入方式与“标准”公式的输入方式不同。 Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. 首先按住CTRL和SHIFT,然后再按Enter,而不是仅按ENTER。 If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself). 如果操作正确,您会注意到Excel在公式周围使用大括号{}(尽管不要尝试自己手动插入大括号)。

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

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