AVERAGETOP

AVERAGETOP(rgeCriteria, iTop)
Returns the average from a range of values only considering the top "x" values

rgeCriteriaThe range of values you want to average.
iTopThe value indicating the top number.

REMARKS
* If "iTop" is greater than the number of items then 0 is returned.
* You can use the user defined AVERAGEVISIBLE function to returns the average value from the visible, non blank cells.
* You can use the user defined AVERAGEVISIBLEIFS function to returns the average value from only the visible, non blank cells that satisfy multiple conditions.
* You can use the user defined AVERAGEAVISIBLE function to returns the average value from the visible, non blank cells.

Public Function AVERAGE_TOP( _ 
         ByVal rgeCriteria As Range, _
         ByVal iTop As Integer) _
         As Single

Dim inumber As Integer
Dim sngAverage As Single

    Call Application.Volatile(True)
    
    If (iTop > rgeCriteria.Cells.Count) Then
        AVERAGE_TOP = 0
        Exit Function
    End If
    
    sngAverage = 0
    For inumber = 1 To iTop
        sngAverage = sngAverage + Application.WorksheetFunction.Large(rgeCriteria, inumber)
    Next inumber
        
    AVERAGE_TOP = sngAverage / iTop
End Function

For instructions on how to add these functions to a workbook refer to the page under Inserting Functions



AVERAGETOP_PERCENT

Returns the average of the visible, non blank cells, only considering the top "x" percent.


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext