The following function returns a “type mismatch”. I don’t understand, as I paid attention to using the “Set” instruction to return my resulting range.
I debugged the function, I get a proper range to return, so the problem is elsewhere.. Hmmmm…
Function getVals(column As String) As Range
Dim col As Variant
col = Application.Match(column, ThisWorkbook.ActiveSheet.Range("1:1"), 0)
Dim rng As Range
Set rng = ThisWorkbook.ActiveSheet.Cells(1, col)
Set rng = rng.Offset(1, 0)
Set rng = Range(rng, rng.End(xlDown))
Set getVals = rng
End Function
Thanks in advance guys for any help 🙂
UPDATE : I am looking at how to send my results as an array. I tried combinations of the function returning “variant”/”variant()” type, and passing rng.value2 as result, but no success.
To return your results as an array of values, simply change the return type to
Variantand returnrng.Value. The below code works for me as long as the passedcolumnstring exists inThisWorkbook.ActiveSheet.Range("1:1").