1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| Sub 方法二() Dim i, j, k Dim ar, br() Dim d As Object, kw$ Set d = CreateObject("Scripting.Dictionary") ar = Range("a1:c" & [a65536].End(3).Row)
ReDim br(1 To UBound(ar), 1 To 1000) Dim rowNum, colNum rowNum = 1: colNum = 1 For i = 2 To UBound(ar) If Not d.exists(ar(i, 2)) Then colNum = colNum + 1 br(1, colNum) = ar(i, 2) d(ar(i, 2)) = colNum End If
If Not d.exists(ar(i, 1)) Then rowNum = rowNum + 1 br(rowNum, 1) = ar(i, 1) d(ar(i, 1)) = rowNum br(rowNum, d(ar(i, 2))) = ar(i, 3) Else br(d(ar(i, 1)), d(ar(i, 2))) = br(d(ar(i, 1)), d(ar(i, 2))) + ar(i, 3) End If
Next i
[f1].Resize(rowNum, colNum) = br Range("f1").Resize(rowNum, colNum).Sort [f1], xlAscending, , , , , , xlYes, , , xlTopToBottom Range("g1").Resize(rowNum, colNum - 1).Sort [g1], xlAscending, , , , , , , , , xlLeftToRight End Sub
|