|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub a()
Dim arr, brr, d1, d2, i, j, sh As Worksheet, mysum%
Set d1 = CreateObject("Scripting.Dictionary")
Set d2 = CreateObject("Scripting.Dictionary")
For Each sh In Sheets
If sh.Name <> "合并库存" Then
arr = sh.[a1].CurrentRegion
For i = 2 To UBound(arr)
d1(arr(i, 1)) = ""
d2(arr(i, 1) & sh.Name) = d2(arr(i, 1) & sh.Name) + arr(i, 2)
Next
End If
Next
[a5:m9999] = ""
[a5].Resize(d1.Count, 1) = Application.Transpose(d1.keys)
arr = [a4].CurrentRegion
For i = 2 To UBound(arr)
For j = 2 To UBound(arr, 2)
arr(i, j) = d2(arr(i, 1) & arr(1, j))
mysum = mysum + arr(i, j)
Next
arr(i, 14) = mysum
mysum = 0
Next
[a4].Resize(UBound(arr), UBound(arr, 2)) = arr
Set d1 = Nothing
Set d2 = Nothing
End Sub |
|