Home » excel » Excel SUM range of cells based on two delimiting values of another range

Excel SUM range of cells based on two delimiting values of another range

Posted by: admin May 14, 2020 Leave a comment

Questions:

My problem:

I have the below tables:

enter image description here

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. When the period changes, the formula needs to be recalculated.

My try:

I started off by using the formula:

=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

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

So when I tried to insert the above formula inside of the SUM formula like this:

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

And then Excel is referecing the cell address itself and not the address inside of the formula.

How to&Answers:

Skip the Addresses and use this based on the months:

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

Answer:

Scott Craner has the right solution for this scenario and it makes more sense here. 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.

INDIRECT function documentation