View Single Post
  #3   Report Post  
Harlan Grove
 
Posts: n/a
Default

Bob Phillips wrote...
....
If you really want a variable number of arguments, then somthing like

Function mySum2(ParamArray inVal())
Dim temp
Dim i As Long

For i = LBound(inVal()) To UBound(inVal())
If IsNumeric(inVal(i)) Then
temp = temp + inVal(i)
End If
Next i
mySum2 = temp
End Function

....

Since when can variable numbers of arguments only consist of scalars?
If you're going to do this right, accept variable numbers of scalar,
range and array arguments.


Function mysum(ParamArray a()) As Double
Dim x AS Variant, Y As Variant

On Error Resume Next

For Each x In a

If TypeOf x Is Range Then
For Each y In x.Cells
mysum = mysum + CDbl(y.Value)
Next y

ElseIf IsArray(x) Then
For Each y In x
mysum = mysum + IIf(IsArray(y), mysum(y), CDbl(y))
Next y

Else
mysum = mysum + CDbl(x)

End If

Next x

End Function


Doing the latter right eliminates the need for the former.