Hello all,
I am trying to develop a function that will give me the average of some numbers in a range that meet certain criteria. Here is the beginning of my code:
It works fine in execution and I even get the correct answer in the immediate window, but when I call the function in a spreadsheet
for some reason I get "#name?" as the result in my cell.
Please help!!
I am trying to develop a function that will give me the average of some numbers in a range that meet certain criteria. Here is the beginning of my code:
Code:
Function AverageBetween(Range As Range, LB As Double, UB As Double, Optional Criteria_Range As Range) As Long
Dim Mycel, SearchRange As Range
Dim n As Long
Dim i As Integer
i = 0
n = 0
Set SearchRange = Range.SpecialCells(xltypeformulas, xlNumbers)
For Each Mycel In SearchRange
If Mycel.Text >= LB And Mycel.Text <= UB Then
n = n + Mycel.Text
i = i + 1
End If
Next
averagebetween = n / i
Debug.Print n
Debug.Print i
Debug.Print averagebetween
End Function
Code:
=PERSONAL.XLSB!AvergeBetween(B49:B54,B50,B52)
Please help!!