SUM "N" Last Rows of DATA
This is my understanding of the requirements:
The DATA
has 2 rows of Headers and other 2 of Totals at the top, therefore an Excel Table
does not apply.
Rows 6:7
are holding the TOTALS TO DATE
and TOTALS LAST PAGE
. TOTALS LAST PAGE
is the SUM
of the last 13
rows of the DATA
. Therefore, we need to identify the last row of the DATA
instead of the last non-blank row.
This solution assumes:
The DATA
is located at range C3:R38
(adjust as required), with the first 4 rows as Header and Totals; and the data details start at row 7
.
In order to be able to calculate the DATA Last Row
we need to identify a field that its last row cell is always populated (i.e. it will never be empty). To demonstrate this solution I assumed that this field is located in column C
. It’s also assumed that the fields for which we need to add the totals are in columns F:R
This solution works with the following three working cells
DATA Last Row
: This FormulaArray
is an important part of the formulas to add the TOTALS LAST PAGE
of several columns (+20 fields), as such having it just once in a working cell, will reduce the resources needed to perform the workbook calculations.
Enter this FormulaArray
in cell I2
(Formulas Array are entered by pressing [Ctrl]
+ [Shift]
+ [Enter]
simultaneously)
=MAX( (C:C <> "" ) * ROW(C:C) )
Last Page Rows
(input from user) : Located at E2
, this working cell holds the number of rows of the last page (number of rows to be added upwards from last row of the DATA
). It provides the flexibility to update the results if the number of rows to add changes, instead of changing each one of the formulas (+20 fields), the user just enters the new number of rows in this cell.
Enter 13
in cell E2
Last Rows to Add (calc)
- Optional : Used to calculate the number of cells to add. To avoid an endless duplication in the case that the DATA
contains less rows than the expected number of rows of the last page. Although this seems to be an unlikely scenario as per the sample data, still added as it could be useful to other users with similar situation. This working cell is optional, as such an alternate formula is provided in case it is not implemented.
Enter this Formula in cell M2
=IF( $I$2 - $E$2 < ROW( $C$7 ), $I$2 - ROW( $C$7 ), $E$2 )
Now to obtain the TOTALS LAST PAGE
we enter one of these formulas in cell F6
and copy to the range G6:R6
a. Last Rows to Add (calc)
working cell implemented
=SUM( OFFSET( INDEX(F:F, $I$2, 0 ), 0, 0, -$M$2 ))
b. Last Rows to Add (calc)
working cell no implemented
=SUM( OFFSET( INDEX(F:F, $I$2, 0 ), 0, 0, -$E$2 ))

Last 13 rows of data are always added, regardless of their contents

Last Rows to Add (calc)
no implemented and DATA
has less than 13
records. TOTALS LAST PAGE
are inaccurate as the total below is also added