英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论