I'm trying to pass a 2D array into a function to return a collection of unique values from the first column.
When I run it I get a compile error ("Compile error: Argument not optional")
This is my code block:
Function uniqueColl(ByVal arr As Variant) As Collection
Dim tempColl As New Collection
For x = 1 To UBound(arr, 2)
tempColl.Add arr(1, x)
Next x
uniqueColl() = tempColl
End Function
I've tried it with the brackets on the last line, without them and filling the brackets with "arr", but none of those things seem to work. Any tips would be much appreciated.
Thank you.
uniqueColl() = tempColl- ditch the brackets, the compiler is parsing that as a recursive call to the function, and your intention is to place a value (or a pointer to it) in the function's return buffer. The correct statement for doing that isSet uniqueColl = tempColl, and I can see that @BZngr has that answer below, in full.