I'm using this code to return an array based on a range. It handles Empty ranges, and 2 or more elements but fails with a single element. I can't puzzle out why. Any ideas?
[VBA]
Sub Arrays()
Dim arr
Dim Ranges(), R
Ranges = Array(Range("B4"), Range("D4"), Range("F4"))
'Pass range start
For Each R In Ranges
x = 12
'assign to variable
arr = TestArray(R)
'loop through elements
For i = 1 To UBound(arr)
'write results
Cells(x, R.Column) = arr(i, 1)
x = x + 1
Next i
Next R
End Sub
Function TestArray(MyRng) As Variant
Dim rng As Range
'Get range
Set rng = Range(MyRng, Cells(Rows.Count, MyRng.Column).End(xlUp))
'Check if Range is empty
If rng(1).Row = 3 Then
'If empty
TestArray = Array()
Else
'If not empty
TestArray = rng.Value
End If
End Function
[/VBA]