I am trying to build a UDF that will accept a ParamArray that will accept one cell, a range of cells, and/or a direct value. I need to then loop through the ParamArray to get all the values passed, but when I try to ReDim an array, it gets stuck and the loop ends. Am I just doing this completely wrong because this just seems like too much work.
Function myudf(first As Variant, ParamArray args() As Variant)
Dim i, j As Long
Dim argsarray() As Variant
ReDim argsarray(0, 0)
For i = 0 To UBound(args)
If Not IsObject(args(i)) Then
ReDim Preserve argsarray(0 To UBound(argsarray) + 1)
argsarray(i) = args(i) ' Handle explicitly passed arguments, e.g. "1,goonie,etc")
ElseIf IsArray(args(i).Value2) Then
For j = 1 To UBound(args(i).Value2)
ReDim Preserve argsarray(0 To UBound(argsarray) + 1)
argsarray(UBound(argsarray) + 1) = args(j).Value2 ' Handle a range of cells, e.g. A1:A3
Next j
Else
ReDim Preserve argsarray(0 To UBound(argsarray) + 1)
argsarray(i) = args(i).Value2 ' Handle individual cells, e.g. A1)
End If
Next i
myudf = Join(argsarray, ",")
End Function