Stack multiple columns VBA Code

rathalex

New Member
Joined
Oct 25, 2017
Messages
32
Hello, I have come across an issue stacking multiple columns in excel 2007. I have 9 columns that need to be stacked up to last non empty cell. The data changes in every column occasionally, so range of each column might be different. There i do need to include Range.End(xlUp) anyhow.... Ive tried range.resize option,but cant seem to get it still. Only was able to stack 2 columns.Any suggestions? Im still new to VBA,so its probably something very simple.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You want to take columns 2 to 8 and paste them all into column (1) is that correct?
 
Upvote 0
If the answer to my question is yes then try this:

Code:
Sub Test()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim Lastrowa As Long
    For i = 2 To 8
        Lastrow = Cells(Rows.Count, "A").End(xlUp).Row + 1
        Lastrowa = Cells(Rows.Count, i).End(xlUp).Row
        Range(Cells(1, i), Cells(Lastrowa, i)).Copy Cells(Lastrow, 1)
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank You My Aswer! The columns I have spread apart pretty far...I need to take data from columns D,BP,BS,BV,BY,CB,CE,CH,CK starting from cell 8 in each and up to last nonempty cell down the bottom. Then stack up them all in column CN starting from CN8 as well.
 
Upvote 0
Try this:
Code:
Sub Test()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim Lastrowa As Long
    For i = 1 To 9
        Lastrow = Cells(Rows.Count, Choose(i, "D", "BP", "BS", "BV", "BY", "CB", "CE", "CH", "CK")).End(xlUp).Row + 1
        If i = 1 Then
            Lastrowa = 8
        Else
        Lastrowa = Cells(Rows.Count, "CN").End(xlUp).Row 'mod
        End If
        Range(Cells(8, Choose(i, "D", "BP", "BS", "BV", "BY", "CB", "CE", "CH", "CK")), Cells(Lastrow, Choose(i, "D", "BP", "BS", "BV", "BY", "CB", "CE", "CH", "CK"))).Copy Cells(Lastrowa + 1, "CN")
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi. My Aswer Is THis - i also have an issue with Stacking columns - i have tried using your first post above and have got it working for i = 5 to 6, which grabs columns E and F as i want it to but it stacks them in to column A in the same sheet. I need to stack them in to Column A in a different sheet i have tried a few things but i cant quite get it to work - any help would be appreciated. TIA
 
Upvote 0
Hi. My Aswer Is THis - i also have an issue with Stacking columns - i have tried using your first post above and have got it working for i = 5 to 6, which grabs columns E and F as i want it to but it stacks them in to column A in the same sheet. I need to stack them in to Column A in a different sheet i have tried a few things but i cant quite get it to work - any help would be appreciated. TIA
I would need to know both sheet names.
Like copy columns C and D from sheet named "Alpha" and paste into column A of sheet named "Bravo"
 
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

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