# Looping row data into column

#### Shaza

##### New Member
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
 firstname lastname id datelogin remarks tom andrew 100010 14/1/2019 enroll new account tom andrew 100010 15/1/2019 update details vincent lew 100020 14/1/2019 enroll new account felicia tan 100030 14/1/2019 enroll new account felicia tan 100030 15/1/2019 update details felicia tan 100030 15/1/2019 set appointment

<tbody>
</tbody>

Outcome(using macro/vba)
 firstname lastname id datelogin remarks datelogin remarks datelogin remarks tom andrew 100010 14/1/2019 enroll new account 15/1/2019 update details vincent lew 100020 14/1/2019 enroll new account felicia tan 100030 14/1/2019 enroll new account 15/1/2019 update details 15/1/2019 set appointment

<tbody>
</tbody>

### Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use \$ signs: \$V\$2:\$Z\$99 will always point to V2:Z99, even after copying
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``````

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.

Replies
28
Views
1K
Replies
8
Views
509
Replies
0
Views
538
Replies
1
Views
409
Replies
3
Views
543

1,202,908
Messages
6,052,488
Members
444,587
Latest member
ezza59

### 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.

### Which adblocker are you using?

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

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