• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Consolidate data in one row

Hi
Please some magic for a macro to move data to one row in excel.
I have added excel example.
Based on column A (unique ID), to move all data from other rows to a single row, so basically all data will be one very very long row.
Example added
 

Attachments

  • Macro to move lines.xlsx
    13.7 KB · Views: 7
Hi:

You can use the following code
Code:
Sub test()
Application.ScreenUpdating = False

k& = 13
c& = 2
Columns("A:k").Sort key1:=Range("A2"), order1:=xlAscending, Header:=xlYes

For i = 2 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
    With Sheet1
        .Range("B" & i & ":K" & i).Copy
        .Cells(c, k).PasteSpecial
        Application.CutCopyMode = False
        k = .Cells(c, .Columns.Count).End(xlToLeft).Column + 1
            If .Range("A" & i) <> .Range("A" & i + 1) Then
                c = c + 1
                k = 13
            End If
    End With
Next

Application.ScreenUpdating = True
End Sub

Out of curiosity, why you want to to mess up a perfectly flat file into this format?As per my experience it is easy to manipulate and make sense out of a flat file than data which is pasted across as one row.

Thanks
 

Attachments

  • Macro to move lines.xlsm
    20.1 KB · Views: 2
I wanted to get the time differences between the flight and I thought it all was in one line, I would just minus one date from the others.
I am looking at the file, and see what you mean.
thank you for your wisdom too.
 
Back
Top