Sum first n columns

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

Example: Sum last n columns

Sum first n columns

METHOD 1. Sum last n columns with headings using Excel formula

EXCEL

=SUM(INDEX(B6:E13,0,1):INDEX(B6:E13,0,C4+1))
This formula uses the Excel SUM and INDEX functions to sum the first n number of columns with selected range that captures the headings. In this example the formula will sum the first two columns from range B6:E13, therefore it will sum the values that are captured in C6 to D13.

METHOD 2. Sum last n columns without headings using Excel formula

EXCEL

=SUM(INDEX(C7:E13,0,1):INDEX(C7:E13,0,C4))
This formula uses the Excel SUM and INDEX functions to sum the first n number of columns with selected range not capturing the headings. In this example the formula will sum the first two columns from range C7:E13, therefore it will sum the values that are captured in C7 to D13.

METHOD 1. Sum last n columns with headings using VBA

VBA

Sub Sum_first_n_columns()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("Analysis")

'sum first 2 columns in a range B6:E13 with the headings being selected in the range
ws.Range("H6").Formula = "=SUM(INDEX(B6:E13,0,1):INDEX(B6:E13,0,C4+1))"

End Sub

METHOD 2. Sum last n columns without headings using VBA

VBA

Sub Sum_first_n_columns()
'declare variables
Dim ws As Worksheet
Set ws = Worksheets("Analysis")

'sum first 2 columns in a range C7:E13, without the heading being selected in the range
ws.Range("H6").Formula = "=SUM(INDEX(C7:E13,0,1):INDEX(C7:E13,0,C4))"

End Sub

Explanation about how to sum first n columns

EXPLANATION

EXPLANATION

This tutorial shows how to sum the first n number of columns in a range using Excel formulas or VBA.
This tutorial provides two Excel and VBA methods that can be used to sum the first n columns from a range.
The first method should be applied where the range captures the headings and the second method should be applied where the range does not capture the headings.
FORMULA (with headings)
=SUM(INDEX(range,0,1):INDEX(range,0,n_num+1))
FORMULA (without headings)
=SUM(INDEX(range,0,1):INDEX(range,0,n_num))
ARGUMENTS
range: The range from which you want to sum the first n number of columns.
n_num: The number of columns 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 add up the last n rows from a specific range 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