Sub Macro1()
Dim arr, brr(), d As Object, ds As Object, i&, s$, t$
Set d = CreateObject("scripting.dictionary")
Set ds = CreateObject("scripting.dictionary")
arr = [a1].CurrentRegion
ReDim brr(1 To UBound(arr), 255)
ReDim crr(UBound(arr))
For i = 2 To UBound(arr)
s = arr(i, 1)
If Not ds.Exists(s) Then
n = n + 1
ds(s) = n
End If
t = arr(i, 2)
If Not d.Exists(t) Then
m = m + 1
d(t) = m
brr(m, 0) = arr(i, 2)
End If
If Len(brr(d(t), ds(s))) Then brr(d(t), ds(s)) = brr(d(t), ds(s)) & "," & arr(i, 3) Else brr(d(t), ds(s)) = arr(i, 3)
Next
[a17].CurrentRegion.ClearContents
[a17] = "部品"
[b17].Resize(, n) = ds.keys
[a18].Resize(m, n + 1) = brr
End Sub |