|
Option Explicit
Sub TEST6()
Dim ar, br, i&, dic As Object, iRSize&, iCSize&, iPosRow&, iPosCol
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
ar = [A1].CurrentRegion.Value
ReDim br(1 To UBound(ar), 1 To UBound(ar))
br(1, 1) = "工厂": iRSize = 1: iCSize = 1
For i = 2 To UBound(ar)
If Not dic.exists(ar(i, 1)) Then
iRSize = iRSize + 1
dic(ar(i, 1)) = iRSize
br(iRSize, 1) = ar(i, 1)
End If
If Not dic.exists(ar(i, 2)) Then
iCSize = iCSize + 1
dic(ar(i, 2)) = iCSize
br(1, iCSize) = ar(i, 2)
End If
iPosRow = dic(ar(i, 1)): iPosCol = dic(ar(i, 2))
br(iPosRow, iPosCol) = br(iPosRow, iPosCol) + ar(i, 5)
Next i
[K1].CurrentRegion.Clear
With [K1].Resize(iRSize, iCSize)
.Value = br
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
End With
Set dic = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
|