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.
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?
View attachment 74953
Yes nothing happen after run and code is good no yellow highlight
 
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.
Thank you for this formula sir, it worked great. Im now need sa vba code this as well and i hope I can get one
 
Upvote 0
A simple, easy to adapt macro based on Post #1
No change needed if the amount of columns change.
Code:
Sub Maybe()
Dim lr As Long, lc As Long, i As Long
lr = Cells(Rows.Count, 2).End(xlUp).Row
lc = Cells(2, Columns.Count).End(xlToLeft).Column
    For i = 2 To lc
        Cells(Rows.Count, lc + 2).End(xlUp).Offset(1).Resize(lr - 1).Value = Cells(2, i).Resize(lr - 1).Value
    Next i
End Sub
 
Upvote 0
A simple, easy to adapt macro based on Post #1
No change needed if the amount of columns change.
Code:
Sub Maybe()
Dim lr As Long, lc As Long, i As Long
lr = Cells(Rows.Count, 2).End(xlUp).Row
lc = Cells(2, Columns.Count).End(xlToLeft).Column
    For i = 2 To lc
        Cells(Rows.Count, lc + 2).End(xlUp).Offset(1).Resize(lr - 1).Value = Cells(2, i).Resize(lr - 1).Value
    Next i
End Sub
Nothing happen as well sir, i think the code did not run after clicking..tried multiple times already
 
Upvote 0
Here's an example of the tool tip:
View attachment 74954
Hi Sir, I tried again the 2nd code, it's now working but the problem is the results are showing on Column H row 52, I don't know why its there, I just notice it just now upon scrolling down. sory, is there a way we can move it up to column H2 instead?
 
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.
Hi Sir, how to change the array? I would like to add 2 more columns (E & F) to make it 5 columns, it's pop up message you can't change part of the array?..can you help me?
 
Upvote 0
Hi Sir, I tried again the 2nd code, it's now working but the problem is the results are showing on Column H row 52, I don't know why its there, I just notice it just now upon scrolling down. sory, is there a way we can move it up to column H2 instead?
The code I created adds the values to the last value present in column H. If there's any data already in column H prior to running the code, it will add it to the bottom.

If you'd like, I can hardcode it so it always starts in row 2. Would that fix your issue?
 
Upvote 0
The code I created adds the values to the last value present in column H. If there's any data already in column H prior to running the code, it will add it to the bottom.

If you'd like, I can hardcode it so it always starts in row 2. Would that fix your issue?
Yes please, the only data present in column H is the header( Result here). If you can move it to H2 that you be very great sir.
 
Upvote 0
Hi Sir, how to change the array? I would like to add 2 more columns (E & F) to make it 5 columns, it's pop up message you can't change part of the array?..can you help me?
Just change the ranges in the formula (whichever one you want). For example:

Rich (BB code):
=IF(ROWS(H$2:H2)>COUNTA($B$2:$D$20),"",INDEX($B$2:$D$20,MOD(ROWS(H$2:H2)-1,COUNTA($A$2:$A$20))+1,INT((ROWS(H$2:H2)-1)/COUNTA($A$2:$A$20))+1))

or

Rich (BB code):
=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)))

Change those to $B$2:$F$100, or whatever you require. If your columns have more data, you may need to change the $20 reference as well in several places. If you have over 1000 rows per column, you'll need to change the 1000's in the second formula to something bigger, like 100000.
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,614
Members
452,661
Latest member
Nonhle

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