ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User-defined Function With Varible Number of Inputs (https://www.excelbanter.com/excel-programming/396702-user-defined-function-varible-number-inputs.html)

Jonas[_3_]

User-defined Function With Varible Number of Inputs
 
I am trying to create a VBA function that will take a variable number
of inputs. Is there a way to declare a variable number of inputs for
a function? I have found that if I don't use the total number of
inputs declared, I will get #Value. My thought is that a loop could
be created to count the number of inputs used in the statement in
Excel =myfunction(input1, input2, input3.....).

This is probably a simple problem but I haven't been able to find the
solution yet.


No Name

User-defined Function With Varible Number of Inputs
 
A ParamArray does that.

Sub fsdadfs()
MsgBox UDFTest("a", "b", "c")
End Sub

Function UDFTest(ParamArray args() As Variant) As String
Dim s As String
Dim i As Integer
For i = LBound(args) To UBound(args)
s = s & args(i) & vbLf
Next
UDFTest = s
End Function




"Jonas" wrote in message
ups.com...
I am trying to create a VBA function that will take a variable number
of inputs. Is there a way to declare a variable number of inputs for
a function? I have found that if I don't use the total number of
inputs declared, I will get #Value. My thought is that a loop could
be created to count the number of inputs used in the statement in
Excel =myfunction(input1, input2, input3.....).

This is probably a simple problem but I haven't been able to find the
solution yet.





All times are GMT +1. The time now is 02:59 AM.

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