Sub PPP()
Dim arr, brr, d As Object, i%, k%, y, p
Set d = CreateObject("Scripting.Dictionary")
arr = Sheet1.Range("A1").CurrentRegion
ReDim brr(1 To UBound(arr), 1 To 3)
For i = 2 To UBound(arr)
If d.exists(arr(i, 2) & "|" & arr(i, 3)) Then
d(arr(i, 2) & "|" & arr(i, 3)) = d(arr(i, 2) & "|" & arr(i, 3)) & "," & arr(i, 1)
Else
d(arr(i, 2) & "|" & arr(i, 3)) = arr(i, 1)
End If
Next
arr = Sheet1.Range("H1").CurrentRegion
k = 1: brr(1, 1) = "编号": brr(1, 2) = "名称": brr(1, 3) = "规格"
For i = 2 To UBound(arr)
p = arr(i, 1) & "|" & arr(i, 2)
If d.exists(p) Then
For Each y In Split(d(p), ",")
If y <> "" Then
k = k + 1
brr(k, 1) = y
brr(k, 2) = arr(i, 1)
brr(k, 3) = arr(i, 2)
End If
Next
End If
Next
[K1].Resize(k, 3) = brr
End Sub
|