Excel macro to move columns to 1 row after each other

brubakes

New Member
Joined
Jul 2, 2015
Messages
2
I was hoping someone could help me write or find a macro that would take two columns and move it to column A under the previous data and repeat for all columns. Basically user information is located in pairs of columns (typeofvalue, value). So column A and B are for user1, column C and D are user2, column E and F are user3, etc. Bonus if I could have a space in between each once moved.

Current:

ABCD
User1FirstUser1LastUser2FirstUser2Last
User1ValueTypeA1User1ValueB1User2ValueTypeA1User2ValueB1
User1ValueTypeA2User1ValueB2User2ValueTypeA1User2ValueB1

<tbody>
</tbody>

Desired:

AB
User1FirstUser1Last
User1ValueTypeA1User1ValueB1
User1ValueTypeA2User1ValueB2
User2FirstUser2Last
User2ValueTypeA1User2ValueB1
User2ValueTypeA1User2ValueB1

<tbody>
</tbody>



Each user has 47 rows of "values", for the example I just did two rows worth.
 
Last edited:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try:
Code:
Sub MoveCols()
    Application.ScreenUpdating = False
    Dim lColumn As Long
    lColumn = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
    Dim x As Long, y As Long
    For x = 1 To lColumn Step 2
        Range(Cells(1, x), Cells(Range("A" & Rows.Count).End(xlUp).Row, x)).Copy Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(2, 0)
    Next x
    For y = 2 To lColumn Step 2
        Range(Cells(1, y), Cells(Range("A" & Rows.Count).End(xlUp).Row, y)).Copy Sheets("Sheet2").Cells(Rows.Count, "B").End(xlUp).Offset(2, 0)
    Next y
    If Sheets("Sheet2").Range("A1") = "" Then
        Sheets("Sheet2").Range("1:2").EntireRow.Delete
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
Code:
Sub MoveCols()
    Application.ScreenUpdating = False
    Dim lColumn As Long
    lColumn = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
    Dim x As Long, y As Long
    For x = 1 To lColumn Step 2
        Range(Cells(1, x), Cells(Range("A" & Rows.Count).End(xlUp).Row, x)).Copy Sheets("Sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(2, 0)
    Next x
    For y = 2 To lColumn Step 2
        Range(Cells(1, y), Cells(Range("A" & Rows.Count).End(xlUp).Row, y)).Copy Sheets("Sheet2").Cells(Rows.Count, "B").End(xlUp).Offset(2, 0)
    Next y
    If Sheets("Sheet2").Range("A1") = "" Then
        Sheets("Sheet2").Range("1:2").EntireRow.Delete
    End If
    Application.ScreenUpdating = True
End Sub


Looks to be good, exactly what I was trying to do. Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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