|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 合并汇总分表数据() '
Application.ScreenUpdating = False
Dim sh As Worksheet
Dim d, arr, brr, s$, i, j, m
Sheet1.Activate
[A1].CurrentRegion.Offset(1).Clear
For Each sh In Sheets
If sh.Name <> "总表" Then
sh.Range("a2").CurrentRegion.Offset(1, 0).Copy [a65536].End(3).Offset(1)
End If
Next
[A1].CurrentRegion.Offset(1).Sort [a2], 1
Set d = CreateObject("scripting.dictionary")
arr = [A1].CurrentRegion
brr = arr
For i = 1 To UBound(arr)
s = arr(i, 1) & arr(i, 2)
If Not d.exists(s) Then
m = m + 1
d(s) = m
For j = 1 To 4
brr(m, j) = arr(i, j)
Next
Else
brr(d(s), 3) = brr(d(s), 3) + arr(i, 3)
End If
Next
[A1].CurrentRegion.Clear
[A1].Resize(m, 4) = brr
Set d = Nothing
Application.ScreenUpdating = True
End Sub |
|