Excel: Passing Array to User Defined Function (VBA)

拜拜、爱过 提交于 2019-12-05 17:17:16

Is this what you mean?

Excel formula:

=sumArray({1,2,3,4,5},2,{9.5,8.7,7.3,6,5,4,3},D1:D11)

UDF:

Function sumArray(ParamArray arr1() As Variant) As Double

    sumArray = WorksheetFunction.Sum(arr1(0)) + arr1(1) + _
        WorksheetFunction.Average(arr1(2)) + WorksheetFunction.Sum(arr1(3))

End Function

update:

The code and formula above definitely work using UK locale with the settings below. If you are getting errors then either substitute the symbols from the control panel or update the formula with the correct list separator and decimal symbol.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!