Concatenate cellls where duplicates exist

Closed
Kavs - Jul 6, 2012 at 07:33 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Jul 6, 2012 at 11:51 PM
Hello,

Part Number Manu Ref
A x
A y
A z
B x
B y
C x
C y
C z

I would like to concatenate the rows where the part number changes so that it shows as follows:

Part Number Manu Fef

A X,Y,Z
B X,Y
C X,Y,Z

Any ideas please, macro or excel formular

Thanks

Gail



1 response

venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Jul 6, 2012 at 11:51 PM
try this macro . the sheet name is Sheet1


Sub test()
Dim r As Range, filt As Range, dest As Range, ra As Range, cdest As Range
Dim part As String, y As String, j As Integer, k As Integer
Worksheets("sheet1").Activate
Range(Range("a1").End(xlDown).Offset(1, 0), Cells(Rows.Count, "A")).EntireRow.Delete

Set r = Range("A1").CurrentRegion
Set dest = Range("A1").End(xlDown).Offset(5, 0)
Set ra = Range(Range("a1"), Range("a1").End(xlDown))
r.Sort key1:=Range("a1"), header:=xlYes

ra.AdvancedFilter xlFilterCopy, , dest, True
Set dest = Range(dest.Offset(1, 0), dest.End(xlDown))
For Each cdest In dest
part = cdest.Value
r.AutoFilter field:=1, Criteria1:=part
Set filt = r.Offset(1, 0).Resize(r.Rows.Count - 1).SpecialCells(12)

j = WorksheetFunction.CountA(filt.Areas(1).Columns("B:B"))

'msgbox j

For k = 1 To j
y = y & "," & filt.Areas(1).Cells(k, 2)
Next k
'msgbox y
y = Right(y, Len(y) - 1)
'msgbox y
cdest.Offset(0, 1) = y
ActiveSheet.AutoFilterMode = False
y = ""
Next cdest

End Sub
0