ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Unlimited # of arguments in a UDF (https://www.excelbanter.com/excel-discussion-misc-queries/227433-unlimited-arguments-udf.html)

FARAZ QURESHI

Unlimited # of arguments in a UDF
 
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()?

Harald Staff[_2_]

Unlimited # of arguments in a UDF
 
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



"FARAZ QURESHI" wrote in message
...
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()?




All times are GMT +1. The time now is 12:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com