Unlimited # of arguments in a UDF

F

FARAZ QURESHI

How to declare the number of arguments to be unlimited and optional, as if
selection of a number of range / cells or insert numbers as if in the
function of =SUM()?
 
H

Harald Staff

Hi Faraz

See if this gets you started:

Public Function myFunction(ParamArray vals() As Variant) As String
Dim L As Long
For L = LBound(vals) To UBound(vals)
myFunction = myFunction & TypeName(vals(L)) & ", "
Next
End Function

Sub Test()
Dim S As String
S = myFunction(Range("A1:C5"), 45, 12.5, "Faraz")
MsgBox S
End Sub

HTH. Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top