|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim ws As Worksheet
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- For Each ws In Worksheets
- If IsNumeric(ws.Name) Then
- With ws
- n = Val(Right(ws.Name, 2)) + 1
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- For j = 1 To UBound(arr, 2)
- If arr(1, j) = "应发合计" Then
- Exit For
- End If
- Next
- If j <= UBound(arr, 2) Then
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 2)) Then
- ReDim brr(1 To 13)
- brr(1) = arr(i, 2)
- Else
- brr = d(arr(i, 2))
- End If
- brr(n) = brr(n) + arr(i, j)
- d(arr(i, 2)) = brr
- Next
- End If
- End With
- End If
- Next
- With Worksheets("汇总")
- .UsedRange.Offset(1, 0).ClearContents
- .Range("a2").Resize(d.Count, UBound(brr)) = Application.Transpose(Application.Transpose(d.items))
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("a1:m" & r).Borders.LineStyle = xlContinuous
- End With
-
- End Sub
复制代码 |
|