简体   繁体   中英

Conditional sum with merged cells using Sumiif()

Scenario is 2 worksheets, Sheet1 and Sheet2.

Sheet1 config:

工作表Sheet1

Sheet2 Config:

Sheet2中

The problem: The customer wants to input the daily amounts of bananas in Sheet2 (C:C) and have the totals automatically add in Sheet1 for the week number. The problem I'm facing with this, I believe is the merged cells. I was successful when I removed the merged cells and added the week number to all the cells with this formula ( =SUMIF(A:A,E3,'Sheet2!C:C) ) But the customer would prefer to keep the merged cells, and with that it only returns the first value of that week. Am I missing something simple here? Can't seem to wrap my head around this.

Merged cells are a bad idea for several reasons and should be avoided.

That does not mean that you can't achieve the look your client wants. You can fill the numbers into all the unmerged cells and then use conditional formatting to hide six of the seven numbers. In the screenshot below, column A has a conditional format with this formula

=MOD((ROW()+2)/7,1)

The format applied is custom number format ;;; (or use white font on white background). Adjust the formula if your data starts on a different row.

Note that the formula bar clearly shows that the selected cell has the value 26.

在此输入图像描述

This is what I found:

=SUM(IF(LOOKUP(ROW(Sheet2!$A$2:$A$15),ROW(Sheet2!$A$2:$A$15)/(Sheet2!$A$2:$A$15<>""),Sheet2!$A$2:$A$15)=A2,Sheet2!$C$2:$C$15))

This is an array formula. Enter into sheet 1 C2. Hit Ctrl Shift Enter . Then copy down.

From my point of view, the important aspect to this specific layout is that a week has 7 days and you are listing every day in the week. A merged cell is identified by the top-left cell in the merged area. Looking for 26 returns A2 and looking for 27 returns A9. If you reference column C with those row numbers and extend the range to 7 rows then you can sum for the matching week.

In G2 (per the image supplied),

'volatile OFFSET function
=SUM(OFFSET(INDEX(C:C, MATCH(E2, A:A, 0)), 0, 0, 7, 1))
'non-volatile INDEX function
=SUM(INDEX(C:C, MATCH(E2, A:A, 0)):INDEX(C:C, MATCH(E2, A:A, 0)+6))

The dates in either table are inconsequential beyond visual reference.

在此输入图像描述

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