Hi everyone,
I have a simple macro below for my purpose. This function always returns 0 if there are error values in the range (e.g. #N/A, #DIV/0!). I feel there is something wrong with the IF statement?
Function CustomAVG(rData As Range, dPct1 As Double, dPct2 As Double, Optional dLower As Double, Optional dUpper As Double) As Double
Dim i As Long, c As Range, a() As Variant
i = -1
On Error Resume Next
For Each c In rData
If Not IsError(c.Value + 0) And (Len(c.Value) > 0) Then
i = i + 1
ReDim Preserve a(i) As Variant
a(i) = c
End If
Next c
CustomAVG = WorksheetFunction.Percentile(a, dPct1)
End Function
Bookmarks