VB code

  • Thread starter Thread starter psinta
  • Start date Start date
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.
 
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)
 
Yes and there more than 3 row. I just put 3 here as an
example.
Thanks for your help.
 
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)
 
Thank you, thank you. I'm sorry to get back to you so
late, got busy at work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top