|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 分类汇总()
Dim d As Object
Dim brr()
Set d = CreateObject("scripting.dictionary")
arr = ThisWorkbook.Worksheets("1月").Range("b2:aw2")
Set Rng = ThisWorkbook.Worksheets("1月").Range("a2:a82")
Application.SheetsInNewWorkbook = 1
Set wb = Workbooks.Add
For j = 1 To UBound(arr, 2)
If InStr(arr(1, j), "合计") = 0 Then
y = 1: n = 2
ReDim brr(1 To 81, 1 To 13)
For Each sh In ThisWorkbook.Worksheets
If sh.Name <> "1-12月" Then
y = y + 1
brr(1, y) = sh.Name
ar = sh.[a1].CurrentRegion
lh = sh.Rows(2).Find(arr(1, j), , , 1).Column
For i = 3 To 82
brr(i - 1, 1) = ar(i, 1)
brr(i - 1, y) = brr(i - 1, y) + ar(i, lh)
Next i
End If
Next sh
Set sht = Worksheets.Add(after:=wb.Worksheets(wb.Worksheets.Count))
sht.Name = arr(1, j)
sht.[a1].Resize(UBound(brr), UBound(brr, 2)) = brr
End If
Next j
wb.SaveAs Filename:=ThisWorkbook.Path & "\汇总表.xlsx"
wb.Close
End Sub
|
|