Using Ranges as Input for User Defined Function

813 views Asked by At

I am trying to write a user defined function that allows me to select two ranges. These ranges are then used to test whether the average of the values in column B is larger or smaller than the weighted averages of values in Column B with weights in column A. The function then returns the larger of the two values to the cell where I input my UDF.

The code I have so far:

Function AVERAGES(RANGE1 As RANGE, RANGE2 As RANGE)
    If Application.WorksheetFuncion.Average(RANGE2) > ((Application.WorksheetFunction.SumProduct(RANGE1, RANGE2) / (Application.WorksheetFunction.Sum(RANGE1)))) Then
        AVERAGES = Application.WorksheetFunction.Average(RANGE2)
    Else
        AVERAGES = (Application.WorksheetFunction.SumProduct(RANGE1, RANGE2) / Application.WorksheetFunction.Sum(RANGE1))
    End If
End Function

It does not return any errors with the code, however the cell in which I type it in to says "#VALUE!".

Any help is appreciated.

0

There are 0 answers