Combine rows using condition
Closed
pankaj.pandey
Posts
1
Registration date
Monday 2 December 2013
Status
Member
Last seen
2 December 2013
-
2 Dec 2013 à 11:59
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 5 Dec 2013 à 10:46
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 5 Dec 2013 à 10:46
Related:
- Combine rows using condition
- Combine notifications viber - Guide
- Combine social media feeds - Guide
- Combine ethernet tethered iphone windows - Guide
- How to delete rows in word - Guide
- How to repeat rows in excel - Guide
1 response
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
5 Dec 2013 à 10:46
5 Dec 2013 à 10:46
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