Forum Discussion

Harry1605's avatar
Harry1605
Copper Contributor
Aug 20, 2022
Solved

Copying multiple columns to two

I have 3,216 columns the odd column numbers hold the email address and the even column numbers hold the group name.  I need to copy or merge the details to the first two columns.  How can I do that? ...
  • HansVogelaar's avatar
    HansVogelaar
    Aug 20, 2022

    Harry1605 

    Ah - I interpreted your request incorrectly.

    If you have an insider version of Microsoft 365, there is probably a formula solution.

    It might also be possible to use PowerQuery.

    But here is a macro solution:

    Sub Combine()
        Dim m As Long
        Dim n As Long
        Dim r As Long
        Dim c As Long
        Dim t As Long
        Application.ScreenUpdating = False
        m = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        n = Cells.Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
        t = Cells(Rows.Count, 1).End(xlUp).Row + 1
        For c = 3 To n Step 2
            m = Cells(Rows.Count, c).End(xlUp).Row
            Cells(t, 1).Resize(m - 3, 2).Value = Cells(4, c).Resize(m - 3, 2).Value
            t = t + m - 3
        Next c
        Application.ScreenUpdating = True
    End Sub

Resources