I am having trouble using the formula below. It works fine in the worksheet, but when used as a custom function an error is returned. The goal is to add everything between the two ranges. I have used the formulaarray because I have to do it that way in the worksheet.

Any suggestions on how to fix this?

Function Bucket_Value(Mcap As Range, Lower_Bound As Double, Upper_Bound As Double) As Double()
Application.Volatile
Bucket_Value = WorksheetFunction.Sum(((((Mcap.FormulaArray) > Lower_Bound) * ((Mcap.FormulaArray) < Upper_Bound)) ^ 2) * (Mcap.FormulaArray))


End Function