简体   繁体   中英

Formula in Excel to add values based on a merged cell

I have a problem: a customer wants to have 14 columns of numbers added up by a client, but the client is on multiple different lines or sometimes only one. Even worse, the client name cells are merged and a VLOOKUP only gives me back the top value. Is there a way to add all the columns under the criteria of client (John for instance in the table below)? And then copy that formula down the list and have it change depending upon the number of times the client's name comes up?

*This is a mock of the problem, all fake info

Column A    Column B    Column C    Column D    Column E
JOHN        500           1000      Total(B:C)  Total for Johns (B:C)'s
            600           6007      Total(B:C)
            550           1000      Total(B:C)
JANE        1200         15220      Total(B:C)  Total for Jane's (B:C)'s
CARL        1400          5430  
            500           5610                  Total for Carl's (B:C)'s
AL          700          15112  
AL          8000          1677  

The last entry concerned me so I have surmised that it is either an anomaly or a typo and 'fixed' it. The remainder of the totals can be collected with a standard formula using row positions garnered through the AGGREGATE¹ function .

下一个非空白条目的总和

The formula in E2 is,

=IF(LEN(A2), SUM(INDEX(B:B,MATCH(A2,A:A,0)):INDEX(C:C, IFERROR(AGGREGATE(15, 6, ROW(2:$9999)/SIGN(LEN(A2:A$9999)), 2)-1, 9999))), "")

If you require a pre-XL2010 solution or need to maintain backwards compatibility to pre-XL2010 versions, post back with version requirements and another (longer and more complicated) version of this formula may be provided.

¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

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