Stack up multiple columns into one VBA

pedexe90

Board Regular
Joined
Apr 18, 2018
Messages
59
Hi everyone,

Can someone please help,

So I have been using this stack up VBA code for the past a few months and everything seemed to work fine. Today, when I tried it, it left gap. So the idea here is to stack up multiple columns into a single column. The issue is that the code misses the first cell of the second column when stacking up and leaves an empty cell instead of the first value (first cell of column G:G.)

Code:
Sub StackUp()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim Lastrowa As Long
    For i = 1 To 12
        Lastrow = Cells(Rows.Count, Choose(i, "C", "G", "K", "O", "S", "W", "AA", "AE", "AI", "AM", "AQ", "AU")).End(xlUp).Row + 1
        If i = 1 Then
            Lastrowa = 2
        Else
        Lastrowa = Cells(Rows.Count, "AY").End(xlUp).Row 'mod
        End If
        Range(Cells(2, Choose(i, "C", "G", "K", "O", "S", "W", "AA", "AE", "AI", "AM", "AQ", "AU")), Cells(Lastrow, Choose(i, "C", "G", "K", "O", "S", "W", "AA", "AE", "AI", "AM", "AQ", "AU"))).Copy Cells(Lastrowa + 1, "AY")
    Next
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Do you mean that G2 does not copied?
If so is that part of a merged cell?
 
Upvote 0
Add following line before ScreenUpdating = True
Code:
Columns("AY").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlup
 
Upvote 0
Does C2, K2, O2 etc get copied over?
What is in G2 a value or a formula?
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,600
Members
452,658
Latest member
GStorm

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