Forum Discussion
ajl_ahmed
Jul 09, 2022Iron Contributor
Combine four columns (multiple columns) vertically into one column
I have four columns with variable heights (I do not know How height), so I need a formula to dynamically discover the height of each column and combine the contents of each column vertically in a new...
- Jul 09, 2022
It depends on which exactly version of Excel 365 you are, as variant
=LET( columnA,FILTER(A:A,A:A<>""), columnB,FILTER(B:B,B:B<>""), columnC,FILTER(C:C,C:C<>""), columnD,FILTER(D:D,D:D<>""), nA,ROWS(columnA), nB,ROWS(columnB), nC,ROWS(columnC), nD,ROWS(columnD), k,SEQUENCE(nA+nB+nC+nD), IF(k<=nA,INDEX(columnA,k), IF(k<=nA+nB,INDEX(columnB,k-nA), IF(k<=nA+nB+nC,INDEX(columnC,k-nA-nB), IF(k<=nA+nB+nC+nD,INDEX(columnD,k-nA-nB-nC), )))) )
OliverScheurich
Jul 09, 2022Gold Contributor
Sub combine()
Dim i As Integer
Dim j As Integer
Dim maxrow As Long
Dim k As Long
Range("E:E").Clear
k = 1
For j = 1 To 4
maxrow = Cells(Rows.Count, j).End(xlUp).Row
For i = 1 To maxrow
Cells(k, 5).Value = Cells(i, j).Value
k = k + 1
Next i
Next j
End Sub
An alternative for older excel versions could be this code. In the attached file one can click the button in cell G2 to run the macro.