|
Sub 月统计()
Application.ScreenUpdating = False
Dim d As Object, dc As Object
Dim ar As Variant, br As Variant
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
Tt = Timer
With Sheet1
R = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:n" & R)
End With
With Sheet2
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs > 3 Then
.Range("a4:m" & rs).Borders.LineStyle = 0
.Range("a4:m" & rs) = Empty
End If
u = UBound(ar)
br = .Range("a3:m" & u)
For j = 2 To UBound(br, 2)
If Trim(br(1, j)) <> "" Then
d(Trim(br(1, j))) = j
End If
Next j
k = 1
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then dc(Trim(ar(i, 1))) = dc(Trim(ar(i, 1))) + 1
If Trim(ar(i, 1)) <> "" And Trim(ar(i, 12)) <> "" Then
T = d(Trim(ar(i, 12)))
If T = "" Then
k = k + 1
d(Trim(ar(i, 12))) = k
T = k
br(k, 1) = ar(i, 12)
End If
lh = d(Trim(ar(i, 1)))
If lh <> "" Then
br(T, lh) = br(T, lh) + 1
End If
End If
Next i
k = k + 1
br(k, 1) = "统计"
br(k + 1, 1) = "月份总笔数"
For j = 2 To UBound(br, 2)
br(k, j) = Application.Sum(Application.Index(br, 0, j))
lh = d(Trim(br(1, j)))
br(k + 1, j) = dc(Trim(br(1, j)))
Next j
.[a3].Resize(k + 1, UBound(br, 2)) = br
.[a3].Resize(k + 1, UBound(br, 2)).Borders.LineStyle = 1
End With
Set d = Nothing
Set dc = Nothing
Application.ScreenUpdating = True
MsgBox "耗时:" & Format(Timer - Tt, "0.00") & "秒"
End Sub
|
评分
-
1
查看全部评分
-
|