Edit

Share via


WorksheetFunction.AverageIf(Range, Object, Object) Method

Definition

Returns the average (arithmetic mean) of all the cells in a range that meet a given criteria.

public double AverageIf (Microsoft.Office.Interop.Excel.Range Arg1, object Arg2, object Arg3);
Public Function AverageIf (Arg1 As Range, Arg2 As Object, Optional Arg3 As Object) As Double

Parameters

Arg1
Range

One or more cells to average.

Arg2
Object

The criteria in the form of a number, expression, cell reference, or text that defines which cells are averaged. For example, criteria can be expressed as 32, "32", ">32", "apples", or B4.

Arg3
Object

The actual set of cells to average. If omitted, range is used.

Returns

Remarks

Cells in range that contain true or false are ignored.

If a cell in range or average_range is an empty cell, AverageIf ignores it.

If a cell in criteria is empty, AverageIf treats it as a 0 value.

If no cells in the range meet the criteria, AverageIf generates an error value.

You can use the wildcard characters, question mark (?) and asterisk (*), in criteria. A question mark matches any single character; an asterisk matches any sequence of characters. If you want to find an actual question mark or asterisk, type a tilde (~) before the character.

Average_range does not have to be the same size and shape as range. The actual cells that are averaged are determined by using the top, left cell in average_range as the beginning cell, and then including cells that correspond in size and shape to range. For example:

A1:A5B1:B5B1:B5
A1:A5B1:B3B1:B5
A1:B4C1:D4C1:D4
A1:B4C1:C2C1:D4

The AverageIf method measures central tendency, which is the location of the center of a group of numbers in a statistical distribution. The three most common measures of central tendency are:

  • Average which is the arithmetic mean, and is calculated by adding a group of numbers and then dividing by the count of those numbers. For example, the average of 2, 3, 3, 5, 7, and 10 is 30 divided by 6, which is 5.
  • Median which is the middle number of a group of numbers; that is, half the numbers have values that are greater than the median, and half the numbers have values that are less than the median. For example, the median of 2, 3, 3, 5, 7, and 10 is 4.
  • Mode which is the most frequently occurring number in a group of numbers. For example, the mode of 2, 3, 3, 5, 7, and 10 is 3.

For a symmetrical distribution of a group of numbers, these three measures of central tendency are all the same. For a skewed distribution of a group of numbers, they can be different.

Applies to