使用数组求和进行用户定义函数 (UDF)。

huangapple go评论75阅读模式
英文:

Using array-summation for UDF

问题

我正在尝试将这个公式设为全局的:

{=SUM(Array1*Array2)}

不是因为我需要这个确切的公式,而是因为我正在尝试弄清楚UDF的语法是如何工作的。我希望结果看起来有点像这样:

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

但这不起作用?有人可以帮助我使用正确的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

答案1

得分: 1

我认为你的UDF1中的UDF名称也不会起作用,所以请更改名称。

可以将你的公式包装在Evaluate调用中,像这样:

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

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

huangapple
  • 本文由 发表于 2020年1月6日 20:37:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612266.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定