Looping row data into column

Shaza

New Member
Joined
Jan 3, 2018
Messages
11
Hi,
I have some repeated data from my database. Is it possible to make it in one row using macro.
For example, for same data user, date login & remarks will loop at next column instead of next row.
Could anyone assist me.

Current data
firstnamelastname iddatelogin remarks
tomandrew10001014/1/2019enroll new account
tomandrew10001015/1/2019update details
vincentlew10002014/1/2019enroll new account
feliciatan10003014/1/2019enroll new account
feliciatan10003015/1/2019update details
feliciatan10003015/1/2019set appointment

<tbody>
</tbody>

Outcome(using macro/vba)
firstnamelastnameiddateloginremarksdateloginremarksdateloginremarks
tomandrew10001014/1/2019enroll new account15/1/2019update details
vincentlew10002014/1/2019enroll new account
feliciatan10003014/1/2019enroll new account15/1/2019update details15/1/2019set appointment

<tbody>
</tbody>
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I am sure there is a better way to do this but here is what I came up with. I assumed your data is like your sample, sorted by ID

Code:
Sub movetorow()
Dim lr As Long
Dim lc As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For x = 2 To lr
    For i = x + 1 To lr
        If Cells(x, "C") = Cells(i, "C") Then
            lc = Cells(x, Columns.Count).End(xlToLeft).Column + 1
            Cells(x, lc) = Cells(i, "D")
            Cells(x, lc + 1) = Cells(i, "E")
            Rows(i).Clear
        End If
    Next i
Next x
lr = Cells(Rows.Count, "A").End(xlUp).Row
For y = lr To 2 Step -1
    If Cells(y, "C") = "" Then Rows(y).Delete
Next y
lc = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
For c = 6 To lc Step 2
    Cells(1, c) = Cells(1, "D")
    Cells(1, c + 1) = Cells(1, "E")
Next c
End Sub
 
Upvote 0
Hi Scott,

Thanks so much for your assistance. This is really helpful. Appreciate your hard work and rigorous effort. Job well done! Amazingly, the results as what required.
 
Upvote 0

Forum statistics

Threads
1,215,653
Messages
6,126,046
Members
449,282
Latest member
Glatortue

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