结合独特的单元格的值

我试图从列A中的列表中获取来自列B的组合值,其中包含重复名称。

Sally Cookies, Apples Jamie Pie Sally Muffins Bob Jam Bob Pie 

结果是:

 Sally Cookies, Apples, Muffins Jamie Pie Bob Jam, Pie 

我已经尝试使用Unique进行sorting,但是我只获取名称的第一个实例

在列A和B中的数据如下:

在这里输入图像描述

运行这个macros:

 Sub GatherData() Dim Na As Long, Nc As Long, v As String Range("A:A").Copy Range("C1") Range("C:C").RemoveDuplicates Columns:=1, Header:=xlNo Na = Cells(Rows.Count, "A").End(xlUp).Row Nc = Cells(Rows.Count, "C").End(xlUp).Row For i = 1 To Nc v = Cells(i, "C").Value Cells(i, "D").Value = "" For j = 1 To Na If v = Cells(j, "A").Value Then Cells(i, "D").Value = Cells(i, "D").Value & "," & Cells(j, "B").Value End If Next j Next i For i = 1 To Nc Cells(i, "D").Value = Mid(Cells(i, "D").Value, 2) Next i End Sub 

会产生:

在这里输入图像描述