|
Sub 统计()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim i As Long, r As Long, rs As Long
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("统计")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r > 1 Then .Range("a2:l" & r) = Empty
ar = .Range("a1:l5000")
For j = 4 To UBound(ar, 2)
If Trim(ar(1, j)) <> "" Then
d(Trim(ar(1, j))) = j
End If
Next j
k = 1
For Each sh In Sheets
If InStr(sh.Name, "月") > 0 Then
rs = sh.Cells(Rows.Count, 1).End(xlUp).Row
y = sh.Cells(1, Columns.Count).End(xlToLeft).Column
br = sh.Range(sh.Cells(1, 1), sh.Cells(rs, y))
For i = 2 To UBound(br)
If Trim(br(i, 2)) <> "" Then
t = d(Trim(br(i, 2)))
If t = "" Then
k = k + 1
d(Trim(br(i, 2))) = k
t = k
For j = 1 To 3
ar(k, j) = br(i, j)
Next j
End If
For j = 4 To y
If Trim(br(i, j)) <> "" Then
If InStr(br(i, j), "*") = 0 Then
sl = Len(Trim(br(i, j)))
For s = 1 To sl
zf = Mid(Trim(br(i, j)), s, 1)
If IsNumeric(zf) Then
lh = s
Exit For
End If
Next s
mc = Left(Trim(br(i, j)), lh - 1)
cs = Val(Right(Trim(br(i, j)), sl - lh + 1))
llh = d(Trim(mc))
If llh <> "" Then
ar(t, llh) = ar(t, llh) + cs
End If
Else
rr = Split(br(i, j), "*")
For s = 0 To UBound(rr)
sl = Len(Trim(rr(s)))
For ss = 1 To sl
zf = Mid(Trim(rr(s)), ss, 1)
If IsNumeric(zf) Then
lh = ss
Exit For
End If
Next ss
mc = Left(Trim(rr(s)), lh - 1)
cs = Val(Right(Trim(rr(s)), sl - lh + 1))
llh = d(Trim(mc))
If llh <> "" Then
ar(t, llh) = ar(t, llh) + cs
End If
Next s
End If
End If
Next j
End If
Next i
End If
Next sh
.[a1].Resize(k, UBound(ar, 2)) = ar
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|