简体   繁体   中英

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'.

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. 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. 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. Thanks in advance.

Assuming that the entries in column C are text, not numeric, array formula** :

=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.

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. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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