Sub test()
Dim dic As Object, data, i%, AA$
Dim bb() As String
Set dic = CreateObject("scripting.dictionary")
data = Range(Cells(1, 1), Cells(1, 2).End(4))
For i = 1 To UBound(data)
AA = data(i, 1)
If Not dic.exists(AA) Then
dic(AA) = data(i, 2)
Else
If InStr(dic(AA), data(i, 2)) = 0 Then
dic(AA) = dic(AA) & "," & data(i, 2)
End If
End If
Next
Cells(1, 3).Resize(dic.Count, 1) = Application.Transpose(dic.keys)
On Error Resume Next
For i = 1 To dic.Count
AA = Cells(i, 3).Value
bb = Split(dic(AA), ",")
Cells(i, 4).Resize(1, UBound(bb) + 1) = bb
Next i
Set dic = Nothing
End Sub作者: kan109 時間: 2018-9-1 00:56
回復 n7822123
上一篇有點小錯,修改如下
Sub test()
Dim dic As Object, data, i%, AA ...
n7822123 發表於 2018-9-1 00:19