HELP how to stack multiple columns into one column. Using (formula or vba code)

usui

Board Regular
Joined
Apr 20, 2020
Messages
55
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hi masters,

Can anyone help me with a formula for stacking multiple columns data into one column. wherein it copies per column not per row.

sample here:
1664380471184.png


I hope anyone has an idea using excel 2016 here..please help me
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Give this a try:
VBA Code:
Sub Consolidate()
Dim lrow As Long
Dim i As Long
Dim j As Long


For i = 2 To 4
    lrow = Cells(Rows.Count, i).End(xlUp).Row
    For j = 2 To lrow
        If Cells(j, i) <> "" Then
            Cells(j, i).Copy Cells(Cells(Rows.Count, 6).End(xlUp).Row + 1, 6)
        End If
    Next j
Next i

End Sub
 
Upvote 0
If the number of items in each column is the same:

Book1 (version 1).xlsb
ABCDEF
1SquareCol 1Col 2Col 3Result
21B1C1D1B1
32B2C2D2B2
43B3C3D3B3
54B4C4D4B4
65B5C5D5B5
76B6C6D6B6
87B7C7D7B7
9C1
10C2
11C3
12C4
13C5
14C6
15C7
16D1
17D2
18D3
19D4
20D5
21D6
22D7
23 
Sheet3
Cell Formulas
RangeFormula
F2:F23F2=IF(ROWS(F$2:F2)>COUNTA($B$2:$D$20),"",INDEX($B$2:$D$20,MOD(ROWS(F$2:F2)-1,COUNTA($A$2:$A$20))+1,INT((ROWS(F$2:F2)-1)/COUNTA($A$2:$A$20))+1))
Press CTRL+SHIFT+ENTER to enter array formulas.


If the number of items in each column can be different:

Book1 (version 1).xlsb
ABCDEF
1SquareCol 1Col 2Col 3Result
21B1C1D1B1
32B2C2D2B2
43B3C3D3B3
54B4D4B4
65B5D5B5
76D6C1
87C2
9C3
10D1
11D2
12D3
13D4
14D5
15D6
16 
Sheet2
Cell Formulas
RangeFormula
F2:F16F2=IF(ROWS(F$2:F2)>COUNTA($B$2:$D$20),"",INDEX($1:$1000,MOD(SMALL(IF($B$2:$D$20<>"",COLUMN($B$2:$D$20)*1000+ROW($B$2:$D$20)),ROWS(F$2:F2)),1000),INT(SMALL(IF($B$2:$D$20<>"",COLUMN($B$2:$D$20)*1000+ROW($B$2:$D$20)),ROWS(F$2:F2))/1000)))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Give this a try:
VBA Code:
Sub Consolidate()
Dim lrow As Long
Dim i As Long
Dim j As Long


For i = 2 To 4
    lrow = Cells(Rows.Count, i).End(xlUp).Row
    For j = 2 To lrow
        If Cells(j, i) <> "" Then
            Cells(j, i).Copy Cells(Cells(Rows.Count, 6).End(xlUp).Row + 1, 6)
        End If
    Next j
Next i

End Sub
It works well, um how about there are 6 columns sir?..and I want the result to show up on Column 8 or H2?

1664382810611.png
 
Upvote 0
Try this. I added two variables that allow you to easily change the # of columns and the destination of the output:
VBA Code:
Sub Consolidate()
Dim lrow As Long
Dim i As Long
Dim j As Long
Dim DestCol As Integer
Dim NumOfCol As Integer

DestCol = 8 'Put the column number you'd like the results to go
NumOfCol = 5 'Put the number of columns that contain data

For i = 2 To NumOfCol + 1
    lrow = Cells(Rows.Count, i).End(xlUp).Row
    For j = 2 To lrow
        If Cells(j, i) <> "" Then
            Cells(j, i).Copy Cells(Cells(Rows.Count, DestCol).End(xlUp).Row + 1, DestCol)
        End If
    Next j
Next i

End Sub
 
Upvote 0
Try this. I added two variables that allow you to easily change the # of columns and the destination of the output:
VBA Code:
Sub Consolidate()
Dim lrow As Long
Dim i As Long
Dim j As Long
Dim DestCol As Integer
Dim NumOfCol As Integer

DestCol = 8 'Put the column number you'd like the results to go
NumOfCol = 5 'Put the number of columns that contain data

For i = 2 To NumOfCol + 1
    lrow = Cells(Rows.Count, i).End(xlUp).Row
    For j = 2 To lrow
        If Cells(j, i) <> "" Then
            Cells(j, i).Copy Cells(Cells(Rows.Count, DestCol).End(xlUp).Row + 1, DestCol)
        End If
    Next j
Next i

End Sub
Nothing happen when I tried this one sir. =(
 
Upvote 0
Do your headers start in column 1 and your Square is in column A? The code requires both of these things to be true.

This code is working in the test wb I'm using.
1664383579671.png
 
Upvote 0
Do your headers start in column 1 and your Square is in column A? The code requires both of these things to be true.

This code is working in the test wb I'm using.
View attachment 74951
Yes sir, all in row1 and starts at column A, but i don't include the data in column A because I'm using it for another formula, so stacking will start at column B only.
 
Upvote 0
Also, the code requires the workbook and sheet you're running the code on to be the active workbook/sheet.
 
Upvote 0
Nothing happens at all? Do you get any errors? If not, can you step through the code and hover over "cells(j,i)" does one of the values that should be copied show up in the yellow tool tip?
1664383812376.png
 
Upvote 0

Forum statistics

Threads
1,224,876
Messages
6,181,522
Members
453,050
Latest member
Obil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top