Combine rows using condition
Closed
pankaj.pandey
Posts
1
Registration date
Monday December 2, 2013
Status
Member
Last seen
December 2, 2013
-
Dec 2, 2013 at 11:59 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen January 16, 2023 - Dec 5, 2013 at 10:46 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen January 16, 2023 - Dec 5, 2013 at 10:46 AM
Related:
- Combine rows using condition
- Combine notifications viber - Guide
- Available memory less than 15mb condition zero - Guide
- How to disable a cell in excel based on condition vba ✓ - Excel Forum
- Excel macro to insert rows between data - Excel Forum
- Excel merge cells if condition met ✓ - Excel Forum
1 response
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
January 16, 2023
549
Dec 5, 2013 at 10:46 AM
Dec 5, 2013 at 10:46 AM
Hi Pankaj,
I put your sample data in column D and E. Make sure that duplicate entry's are adjacent to each other as they are now (use sort if they are not).
The following code will put result in columns A, B and C:
Best regards,
Trowa
I put your sample data in column D and E. Make sure that duplicate entry's are adjacent to each other as they are now (use sort if they are not).
The following code will put result in columns A, B and C:
Sub RunMe() Dim lRow As Integer lRow = Range("D1").End(xlDown).Row For Each cell In Range("D1:D" & lRow) If cell.Value = Range("A" & Rows.Count).End(xlUp).Value Then Range("B" & Rows.Count).End(xlUp) = Range("B" & Rows.Count).End(xlUp) & ", " & cell.Offset(0, 1) Range("C" & Rows.Count).End(xlUp) = Range("C" & Rows.Count).End(xlUp) + 1 Else Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = cell.Value Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = cell.Offset(0, 1).Value Range("C" & Rows.Count).End(xlUp).Offset(1, 0) = 1 End If Next cell End Sub
Best regards,
Trowa