Sum last n rows

This tutorial shows how to add up the last n rows from a specific range using an Excel formula or VBA

Example: Sum last n rows

Sum last n rows

METHOD 1. Sum last n rows using Excel formula

EXCEL

=SUM(INDEX(C7:E13,ROWS(C7:E13)-(C4-1),0):INDEX(C7:E13,ROWS(C7:E13),0))
This formula uses the Excel SUM, INDEX and ROWS functions to sum the last n number of rows. In this example the formula will sum the last two rows from range C7:E13, therefore it will sum the values that are captured in C12 to E13.

METHOD 1. Sum last n rows using VBA

VBA

Sub Sum_last_n_rows()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'sum last 2 rows in a range C7:E13

ws.Range("G7").Formula = "=SUM(INDEX(C7:E13,ROWS(C7:E13)-(C4-1),0):INDEX(C7:E13,ROWS(C7:E13),0))"

End Sub

Explanation about how to sum last n rows

EXPLANATION

EXPLANATION

This tutorial shows how to add up the last n number of rows from a specific range through the use of an Excel formula or VBA.
The Excel and VBA methods both use the SUM, INDEX and ROWS functions to return the sum of the nominated number of rows from a specific range.
FORMULA
=SUM(INDEX(range,ROWS(range)-(n_num-1),0):INDEX(range,ROWS(range),0))
ARGUMENTS
range: The range from which you want to sum the last n number of rows.
n_num: The number of rows that you want to sum from a selected range.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to add up the last n columns from a specific range using Excel and VBA
How to sum the last n values in a column using Excel and VBA

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel SUM function returns the sum of all numbers in a specified range
The Excel INDEX function returns a value that is referenced from a specified range
The Excel ROWS function returns the number of rows in a specified array