Average numbers and ignore zeros

This tutorial shows how to average numbers in a range and ignore zeros through the use of an Excel formula or VBA

Example: Average numbers and ignore zeros

Average numbers and ignore zeros

METHOD 1. Average numbers and ignore zeros

EXCEL

=AVERAGEIF(B5:B11,"<>0")
This formula uses the Excel AVERAGEIF function with the "<>0" criteria, which means does not equal to zero, to return the average of the numbers captures in the specified range (B5:B11), whilst ignoring cells that contain only a value of zero.

METHOD 1. Average numbers and ignore zeros using VBA

VBA

Sub Average_numbers_ignore_zeros()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'average numbers ignoring zeros
ws.Range("D5") = Application.WorksheetFunction.AverageIf(Range("B5:B11"), "<>0")

End Sub

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("D5") in the VBA code.
Range: Select the range which captures the numbers that you want to average, ignoring zeros, by changing the range reference ("B5:B11") in the VBA code.
Worksheet Selection: Select the worksheet which captures a range of cells from which you want to average the numbers by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name 'ws' in the VBA code.

Explanation about the formula used to average numbers ignoring zeros

EXPLANATION

EXPLANATION

This tutorial shows how to average numbers in a range, that contains zeros, and ignore zeros through the use of an Excel formula or VBA
FORMULA
=AVERAGEIF(range,"<>0")
ARGUMENTS
range: A range of cells which you want to average, ignoring zeros.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to average numbers that are greater than a specific value using Excel and VBA methods
How to average numbers that are less than a specific value using Excel and VBA methods
How to average only positive numbers in a specified range using Excel and VBA methods
How to average all values in a single column using Excel and VBA methods
How to sum cells and ignore errors using Excel and VBA methods

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel AVERAGEIF function returns the average of the numbers in a specified range based on a single criteria