|
Sub 汇总()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim ar As Variant
Dim d As Object
Dim br()
Set d = CreateObject("scripting.dictionary")
With Sheets("sheet0")
r = .Cells(Rows.Count, 1).End(xlUp).Row
y = .Cells(1, Columns.Count).End(xlToLeft).Column
If r < 2 Or y < 3 Then MsgBox "数据表为空!": End
ar = .Range(.Cells(1, 1), .Cells(r, y))
End With
ReDim br(1 To UBound(ar), 1 To 1000)
br(1, 1) = "车牌号"
y = 1: k = 2
For i = 2 To UBound(ar)
If ar(i, 1) <> "" Then
t = d(ar(i, 1))
If t = "" Then
k = k + 1
d(ar(i, 1)) = k
t = k
br(k, 1) = ar(i, 1)
End If
For j = 3 To UBound(ar, 2)
zd = ar(i, 2) & "|" & ar(1, j)
lh = d(zd)
If lh = "" Then
y = y + 1
d(zd) = y
lh = y
br(1, y) = ar(i, 2)
br(2, y) = ar(1, j)
End If
br(t, lh) = br(t, lh) + Val(ar(i, j))
Next j
End If
Next i
With Sheets("汇总")
.[a1].CurrentRegion.Clear
.[a1].Resize(k, y) = br
.[a1].Resize(k, y).Borders.LineStyle = 1
ls = UBound(ar, 2) - 2
For j = 2 To y Step ls
.Cells(1, j).Resize(1, ls).Merge
Next j
.Rows("1:1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|