How to pass a dynamic array of “strings” to a function as an argument?
How to pass a dynamic array of “strings” to a function as an argument?
Guessing a bit here, but if you mean the number of strings you want to pass is dynamic, try ParamArray. See vba help and not that it must be the last arg and a variant.
Hope that helps,Sub exa() Call test("one") Call test("One", "Two") End Sub Function test(ParamArray MyStrings() As Variant) Dim i As Long For i = LBound(MyStrings) To UBound(MyStrings) MsgBox MyStrings(i) Next End Function
Mark
We can't specify the datatype here. Because It will create complexities in Validations. Thank you.
Worksheet function or VBA function?
Paul
I think he wants to pass a dynamic array to a sub as a By Ref.
ie.
[vba]
Sub SomeSub()
Dim SomeDynamicArray as String
MySub SomeDynamicArray
End Sub
Sub MySub(MyArray)
Do Something with MyArray 'SomeDynamicArray
End Sub
[/vba]