数据较多时应避免使用Transpose函数转置
Sub Macro2()
Dim arr, brr(), d As Object, i&, j%, m&
Set d = CreateObject("scripting.dictionary")
arr = Range("A1").CurrentRegion
ReDim brr(1 To UBound(arr) * UBound(arr, 2) / 2, 1 To 2)
For j = 1 To UBound(arr, 2) Step 2
For i = 2 To UBound(arr)
If Len(arr(i, j)) = 0 Then Exit For
If Not d.Exists(arr(i, j)) Then
m = m + 1
d(arr(i, j)) = m
brr(m, 1) = arr(i, j)
brr(m, 2) = arr(i, j + 1)
Else
brr(d(arr(i, j)), 2) = brr(d(arr(i, j)), 2) + arr(i, j + 1)
End If
Next
Next
Range("K2:L65536").ClearContents
Range("K2").Resize(m, 2) = brr
End Sub
|