|
Sub test()
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheet1
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:a" & r)
rs = .Cells(Rows.Count, 5).End(xlUp).Row
.Range("b2:d" & rs) = Empty
br = .Range("b1:e" & r)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = ""
End If
Next i
For i = 2 To UBound(br)
sl = 0
For Each k In d.keys
If InStr(br(i, 4), k) > 0 Then
sl = sl + 1
If sl = 1 Then
br(i, 2) = k
ElseIf sl > 1 Then
If br(i, 3) = "" Then
br(i, 3) = k
Else
br(i, 3) = br(i, 3) & "," & k
End If
End If
End If
Next k
br(i, 1) = sl
Next i
.[b1].Resize(UBound(ar), 3) = br
End With
MsgBox "ok!"
End Sub
|
|