I am trying to design a function that grabs an average of only numbers that are within a certain deviation of the mean. I got the plan down, and have done this before without VBA, its just a user defined function will be much quicker.
The gist of what I am doing:
Find the standard deviation of a range and then only find the average of numbers that fall within n deviations from the mean. I am stuck with the part that I would normally use an array code for. Here is what my array would look like:
{=AVERAGE(IF((nums>high)*(nums<low),nums))}
<low),nums))}
[]
<low),nums))}
There are a couple ways I thought of tackling this, but not so elegant due to my newbie level of VBA
Appreciate your replies.</low),nums))}></low),nums))}
The gist of what I am doing:
Find the standard deviation of a range and then only find the average of numbers that fall within n deviations from the mean. I am stuck with the part that I would normally use an array code for. Here is what my array would look like:
{=AVERAGE(IF((nums>high)*(nums<low),nums))}
<low),nums))}
[]
<low),nums))}
Code:
Function ConfidenceAvg(nums As Range) As Double
Dim stdDev As Double
Dim high As Double
Dim low As Double
Dim average As Double
stdDev = WorksheetFunction.StDev_S(nums)
average = WorksheetFunction.average(nums)
high = average + stdDev 'one deviation from mean
low = average - stdDev 'one deviation from mean
'enter array loop here to get only specified averages
ConfidenceAvg =
End Function
There are a couple ways I thought of tackling this, but not so elegant due to my newbie level of VBA
Appreciate your replies.</low),nums))}></low),nums))}
Last edited: