Using array-summation for UDF

I am trying to make this formula global:

{=SUM(Array1*Array2)}

Not because I need this exact formula, but because I am trying to figure out how the syntax works for UDF. I'm hoping that the result looks a little like this::

Public Function UDF1(MyArray1 As Range, MyArray2 As Range)
UDF1 = WorksheetFunction.Sum(MyArray1 * MyArray2)
End Function

But this doesn't work? Is there anybody who could help me use the correct syntax for UDF

Upvotes: 1

Views: 92

Answers (1)

EvR
EvR

Reputation: 3498

I think the UDF name in your UDF1 will also not work, so change the name.

You could wrap your formula in an Evaluate call like this:

Public Function testing(MyArray1 As Range, MyArray2 As Range)
    testing = Evaluate("SUM(" & MyArray1.Address & "*" & MyArray2.Address & ")")
End Function

Upvotes: 1

Related Questions