忘了,闪屏呢
Sub 合计()
Application.ScreenUpdating = False '关闭屏幕刷新
Application.Calculation = xlCalculationManual '手动重算
Dim dic As Object
Dim arr, brr()
Dim i As Long
Dim xh, n, m
Sheets("明细").Activate
arr = Range("b1").CurrentRegion
Set dic = CreateObject("scripting.dictionary") '建立字典对象dic
ReDim brr(1 To UBound(arr), 1 To 12)
For i = 2 To UBound(arr)
xh = arr(i, 3) '& arr(i, 3) & arr(i, 4) & arr(i, 5) & arr(i, 6)
If Not dic.exists(xh) Then
n = n + 1
dic(xh) = n
brr(n, 1) = arr(i, 2)
brr(n, 2) = arr(i, 3)
brr(n, 3) = arr(i, 4)
brr(n, 4) = arr(i, 5)
brr(n, 5) = arr(i, 6)
brr(n, 6) = arr(i, 10)
Else
m = dic(xh)
brr(m, 6) = brr(m, 6) + arr(i, 10)
' brr(m, 2) = brr(m, 2) + arr(i, 3)
End If
Next i
Application.Calculation = xlCalculationAutomatic '自动重算
Sheets("合计").Activate
Columns("m:r").Clear
' Range("m2").Resize(dic.Count, 1) = Application.Transpose(dic.keys)
Sheets("合计").Range("a3").Resize(dic.Count, 6) = brr
End Sub
|