ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB code (https://www.excelbanter.com/excel-programming/299473-re-vbulletin-code.html)

Bob Phillips[_6_]

VB code
 
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)

"psinta" wrote in message
...
Yes and there more than 3 row. I just put 3 here as an
example.
Thanks for your help.

-----Original Message-----
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)

"psinta" wrote in message
...
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.





.




psinta

VB code
 
Thank you, thank you. I'm sorry to get back to you so
late, got busy at work.


-----Original Message-----
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)

"psinta" wrote in message
...
Yes and there more than 3 row. I just put 3 here as an
example.
Thanks for your help.

-----Original Message-----
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)

"psinta" wrote in message
...
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.





.



.



All times are GMT +1. The time now is 05:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com