VB code

P

psinta

Help, is there a way to write a code to make these three
row of data into one row:
Label Grade Teacher FirstName LastName
2015 05 Booney Juan Alva
2018 05 Booney Bailey Bol
2021 05 Booney Ryan Dame

Thank you in advance.
 
B

Bob Phillips

What are the rules? Do you want 5 cells for row 1, followed by the 5 for row
2, etc.? And are there more rows or just 3?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
P

psinta

Yes and there more than 3 row. I just put 3 here as an
example.
Thanks for your help.
 
B

Bob Phillips

Here's some code for it

Sub test()
Dim cLastRow As Long
Dim i As Long
Dim j As Long
Dim rng As Range

cLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To cLastRow
j = 0
Do While Cells(i, "C").Value = Cells(i + j + 1, "C").Value
j = j + 1
Cells(i + j, "A").Resize(1, 5).Copy Cells(i, 5 * j + 1)
If rng Is Nothing Then
Set rng = Cells(i + j, "A")
Else
Set rng = Union(rng, Cells(i + j, "A"))
End If
Loop
i = i + j
Next i

If Not rng Is Nothing Then
rng.EntireRow.Delete
End If

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top