简体   繁体   English

Excel SUM单元格范围基于另一个范围的两个定界值

[英]Excel SUM range of cells based on two delimiting values of another range

My problem: 我的问题:

I have the below tables: 我有下表:

在此处输入图片说明

In my second table (tbl_analysis), I need to create a formula in the Sum column that will sum the salary of a certain person over a certain period. 在我的第二张表(tbl_analysis)中,我需要在“总计”列中创建一个公式,该公式将在一定时期内某个人的薪水相加。 When the period changes, the formula needs to be recalculated. 当时间段更改时,需要重新计算公式。

My try: 我的尝试:

I started off by using the formula: 我首先使用以下公式:

=SUM(my_range) = SUM(my_range)

By the range can't be hard-coded, so I decided to find the cell address of the corresponding month as you can see in the range D12:E15 由于范围不能被硬编码,所以我决定找到相应月份的单元格地址,如您在范围D12:E15中所见

Formula in the cell D12: =CELL("address",INDEX($A$2:$M$8,MATCH(A12,$A$2:$A$8,0),MATCH(B12,$A$2:$M$2,0))) 单元格D12中的公式:= CELL(“地址”,INDEX($ A $ 2:$ M $ 8,MATCH(A12,$ A $ 2:$ A $ 8,0),MATCH(B12,$ A $ 2:$ M $ 2, 0)))

So when I tried to insert the above formula inside of the SUM formula like this: 因此,当我尝试将上述公式插入SUM公式中时,如下所示:

=SUM( CELL("address",INDEX($A$2:$M$8,MATCH(A12,$A$2:$A$8,0),MATCH(B12,$A$2:$M$2,0))) : CELL("address",INDEX($A$2:$M$8,MATCH(A12,$A$2:$A$8,0),MATCH(C12,$A$2:$M$2,0))) ) = SUM( CELL(“ address”,INDEX($ A $ 2:$ M $ 8,MATCH(A12,$ A $ 2:$ A $ 8,0),MATCH(B12,$ A $ 2:$ M $ 2,0)))CELL(“地址”,INDEX($ A $ 2:$ M $ 8,MATCH(A12,$ A $ 2:$ A $ 8,0),MATCH(C12,$ A $ 2:$ M $ 2,0)))

And then Excel is referecing the cell address itself and not the address inside of the formula. 然后,Excel将引用单元格地址本身而不是公式内部的地址。

跳过地址,并根据月份使用此地址:

=SUM(INDEX(A:M,MATCH(A12,A:A,0),MATCH(B12,$2:$2,0)):INDEX(A:M,MATCH(A12,A:A,0),MATCH(C12,$2:$2,0)))

Scott Craner has the right solution for this scenario and it makes more sense here. Scott Craner为这种情况提供了正确的解决方案,在这里更有意义。 However if you would absolutely need to get cell reference from a cell you would be able to do it using the following function: 但是,如果您绝对需要从某个单元格获取单元格引用,则可以使用以下函数进行操作:

INDIRECT(cell) 

Usually this isn't necessary but it can be handy when you want to break up a long formula where you would need to find a row number for example. 通常这不是必需的,但是当您想要分解一个长公式(例如需要查找行号)时,它会很方便。

INDIRECT("A" & B2) 

Where B2 has the row number for a dynamic range or specific moving target row. 其中B2具有动态范围或特定移动目标行的行号。

INDIRECT function documentation 间接功能文档

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

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