|
Option Explicit
Sub TEST6()
Dim ar, br, i&, r&, c&, iPosRow&, iPosCol&, dic As Object
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
ar = Worksheets(1).[A1].CurrentRegion.Value
ReDim br(1 To UBound(ar), 1 To UBound(ar))
r = 1: c = 1: br(1, 1) = "车牌号"
For i = 2 To UBound(ar)
If Not dic.exists(ar(i, 3)) Then
r = r + 1
dic(ar(i, 3)) = r
br(r, 1) = ar(i, 3)
End If
If Not dic.exists(ar(i, 4)) Then
c = c + 1
dic(ar(i, 4)) = c
br(1, c) = ar(i, 4)
End If
iPosRow = dic(ar(i, 3)): iPosCol = dic(ar(i, 4))
br(iPosRow, iPosCol) = br(iPosRow, iPosCol) + ar(i, 5)
Next i
With Worksheets(2)
.Cells.Clear
With .[A1].Resize(r, c)
.Value = br
.Borders.LineStyle = xlContinuous
.EntireColumn.AutoFit
End With
.Activate
End With
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
|