|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
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
.Range(.Cells(3, 6), .Cells(r + 1, 12)) = Empty
ar = .Range(.Cells(2, 1), .Cells(r, 12))
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = i
End If
Next i
For j = 6 To UBound(ar, 2)
If Trim(ar(1, j)) <> "" Then
d(Trim(ar(1, j))) = j
End If
Next j
For Each sh In Sheets
If sh.Name <> "总表" Then
rs = sh.Cells(Rows.Count, 1).End(xlUp).Row
br = sh.Range("a1:i" & rs)
For i = 2 To UBound(br)
If Trim(br(i, 2)) <> "" Then
xh = d(Trim(br(i, 2)))
lh = d(Trim(br(i, 8)))
If xh <> "" And lh <> "" Then
ar(xh, lh) = ar(xh, lh) + br(i, 9)
End If
End If
Next i
End If
Next sh
.Range(.Cells(2, 1), .Cells(r, 12)) = ar
End With
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|