Sub tt()
Dim Dic
Dim i, j, n, m
Dim arr, brr(1 To 10000, 1 To 8)
Sheets("结果").Range("a2:h1000").ClearContents
Set Dic = CreateObject("scripting.dictionary")
arr = Sheets("数据源").Range("a1").CurrentRegion
For i = 2 To UBound(arr, 1)
For j = 2 To UBound(arr, 2)
If arr(i, j) <> "" Then
If Dic.exists(arr(i, 1)) Then
x = Dic(arr(i, 1))
If j < UBound(arr, 2) Then
brr(x, j) = brr(x, j) & "、" & arr(i, j)
Else
brr(x, 1) = arr(i, 1)
brr(x, j) = brr(x, j) + arr(i, j)
End If
Else
n = n + 1
Dic(arr(i, 1)) = n
brr(n, j) = arr(i, j)
End If
End If
Next
Next
Sheets("结果").Range("a2").Resize(n, 8) = brr
End Sub |