Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 49956

Combing rows with duplicate and unique data

$
0
0
current I have a macro that will consolidate rows when data in column a matches. the unique data from the other columns will combine into the same row separated by commas. The issue with the macro is that it doesn't filter out duplicates. for instances if A3 matches A10, it will marge the rows together and if data from the other columns are the same, it will only keep 1 version and if they are unique, it will combine them in the same row separated by commas.

Sub CombineRows()
Dim LR As Long, r As Long, c As Long

Application.ScreenUpdating = False
LR = Range("A" & Rows.Count).End(xlUp).Row
For r = LR To 3 Step -1
With Cells(r, "A")
If .Value = .Offset(-1).Value Then
For c = 1 To 4
If .Offset(, c).Value <> "" Then
.Offset(-1, c).Value = .Offset(-1, c).Value _
& ", " & .Offset(, c).Value
End If
Next c
Rows(r).Delete
End If
End With
Next r
Columns("H:K").AutoFit
Application.ScreenUpdating = True
End Sub

Viewing all articles
Browse latest Browse all 49956

Trending Articles