我正在尝试从列A中包含重复名称的列表中获取列B中的组合值。
Sally Cookies, Apples
Jamie Pie
Sally Muffins
Bob Jam
Bob Pie
并得到结果:
Sally Cookies, Apples, Muffins
Jamie Pie
Bob Jam, Pie
我尝试使用Unique进行排序,但我只获得名称的第一个实例
答案 0 :(得分:1)
列中的数据 A& B 喜欢:
运行此宏:
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
将产生: