两个都可以,第二个不能引用 单元格区域,每个单元格都是一个参数,需要用逗号分隔
第一个比较接近内置函数SUM'
Option Explicit
Function Ssum(ByVal range As range) As Double
Dim rng As range
For Each rng In range
Ssum = Ssum + rng.Value
Next rng
End Function
Function Ssum0(ParamArray arr()) As Double
Dim i As Integer
For i = LBound(arr) To UBound(arr)
If IsNumeric(arr(i)) Then
Ssum0 = Ssum0 + arr(i)
End If
Next i
End Function
如下:
Function sum0(ByVal Rng As Range) As Double
Dim t, R
t = 0
For Each R In Rng
t = t + R.Value
Next
sum0 = t
End Function