I am trying to create a function as follows:
Input: range
Output: column that contains all the non-empty cells in the range.
For example, on input
A | B | C | D
--------------
1 | 2 | | 3
4 | | 5 |
The output should be
A
--
1
2
3
4
5
Here's my trial:
Function toColumn(range As range) As Integer()
Dim res(,) As Integer, i As Integer
i = 0
For Each Row In range.Rows
For Each cel In Row.Cells
If Not IsEmpty(cel) Then
ReDim Preserve res(0, i)
res(0, i) = cel
i = i + 1
End If
Next cel
Next Row
toColumn = res
End Function
I know that a variant of this where res was one dimensional (and thus, the result was a row rather than a column) worked for me. So, the problem is with being it two dimensional.
Also, I know that there's a problem specifically with the decleration
Dim res(,) As Integer
but I can't figure out what's the problem.
Thanks in advance!