Function ConcatenateAndSum(Employee As String, ParamArray Numbers() As Variant) As String
Dim X As Long, Total As Double
For X = LBound(Numbers) To UBound(Numbers)
Total = Total + Numbers(X)
Next
ConcatenateAndSum = Employee & "'s Total: " & Total
End Function
Optional arguments must come after all mandatory arguments in the list of argument (if any... it is possible to have only Optional arguments if you wish to). To declare an argument as Optional, you simply precede its name in the argument list with the keyword Optional...In addition, since you mention about optional arguments.
How do I define them in UDF?
Function MyUDF(UserName As String, City As String, State As String, Optional TelephoneNumber As String, Optional FaxNumbare As String) As Variant
Function PI(Optional MaxNumberOfDecimalPlaces As Long = 8) As String
PI = 4 * Atn(1)
PI = Round(PI, MaxNumberOfDecimalPlaces)
End Function
=PI() ==> 3.14159265
=PI(3) ==> 3.142
=PI(6) ==> 3.141593