Average first n values in a row

To average the first n values in a row you can use a combination of Excel AVERAGE and OFFSET functions, using Excel and VBA

Example: Average first n values in a row

Average first n values in a row

METHOD 1. Average first n values in a row

EXCEL

=AVERAGE(OFFSET(C4,0,0,,I5))
This formula averages the first n values from a specific row, using a combination of the Excel AVERAGE and OFFSET functions. In this example the formula averages the first three values (the number is captured in cell I5 and referenced in the formula) in row 4.
Please note that if there is a blank cell or a non numeric value in the row the formula will take this cell into consideration and will apply a value of 0 against the cell.

METHOD 1. Average first n values in a row using VBA

VBA

Sub Average_first_n_values_in_a_row()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'average the first three values in a row
ws.Range("J5") = Application.Average(Range("C4").Offset(0, 0).Resize(1, Range("I5")))

End Sub

PREREQUISITES
Worksheet Name: Have a worksheet named Analysis.
First cell in range: If using the exact same VBA code, the first cell in a range needs to be ("C4").
First n values: In this example we are referencing to a cell ("I5") that contains a number of the first n values to average. Therefore, if using the exact same VBA code you will need to capture a number of the first n values in cell ("I5").
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell references ("J5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
First cell in range: Select the first cell in a range (row) from which to average the first n values by changing the cell reference ("C4") in the VBA code to any cell that doesn't conflict with the formula.
First n values: Select the first number of values that you want to average in the specified row by changing the cell reference ("I5") in the VBA code to any cell that contains the number and doesn't conflict with the formula. You can also enter the number directly in the VBA code, by replacing 'Range("I5")' with a number.

Explanation about how to average first n values in a row

EXPLANATION

EXPLANATION
This tutorial shows and explains how to average first n values in a row, by using an Excel formula or VBA.

Excel Method: This tutorial provides a single Excel method that can be applied to average first n values in a row, using a combination of Excel AVERAGE and OFFSET functions.

VBA Methods: This tutorial provides a single VBA method that averages first n values in a row by applying the AVERAGE and OFFSET functions in the VBA code.

FORMULA
AVERAGE(OFFSET(first_cell,0,0,,first_n_values))
ARGUMENTS
first_cell: The first cell in a specific row from which to begin averaging the first n values.
first_n_values: A number that represents the first n values to be averaged.
ADDITIONAL NOTES
Note 1: If a blank cell or a non-numeric value is captured in the first n values to be averaged, the formula treats these the same as 0.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to average the last n values in a column using Excel and VBA methods
How to average the first n values in a row using Excel and VBA methods
How to sum cells with values in odd columns using Excel and VBA methods
How to sum cells with values in even columns using Excel and VBA methods
How to sum the first n values in a column using Excel and VBA methods

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel AVERAGE function returns the average value from a specified range