|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet2")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:m" & r)
- For i = 1 To UBound(arr)
- arr(i, 1) = CDate(arr(i, 1))
- yf = Month(arr(i, 1))
- rq = Day(arr(i, 1))
- If Not d.exists(arr(i, 4)) Then
- Set d(arr(i, 4)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 4)).exists(0) Then
- ReDim crr(1 To 6)
- crr(1) = arr(i, 9)
- crr(2) = arr(i, 4)
- crr(3) = arr(i, 11)
- Else
- crr = d(arr(i, 4))(0)
- End If
- If Not d(arr(i, 4)).exists(yf) Then
- ReDim brr(1 To 7, 1 To 32)
- Else
- brr = d(arr(i, 4))(yf)
- End If
- brr(1, rq) = brr(1, rq) + arr(i, 7)
- brr(2, rq) = brr(2, rq) + arr(i, 8)
- brr(3, rq) = arr(i, 10)
- brr(4, rq) = brr(4, rq) + arr(i, 6)
- brr(5, rq) = arr(i, 5)
- brr(6, rq) = arr(i, 12)
- brr(7, rq) = arr(i, 13)
- brr(1, 32) = brr(1, 32) + arr(i, 7)
- brr(2, 32) = brr(2, 32) + arr(i, 8)
- brr(4, 32) = brr(4, 32) + arr(i, 6)
- d(arr(i, 4))(yf) = brr
- crr(4) = crr(4) + arr(i, 7)
- crr(5) = crr(5) + arr(i, 8)
- crr(6) = crr(6) + arr(i, 6)
- d(arr(i, 4))(0) = crr
- Next
- End With
- For Each aa In d.keys
- With Worksheets("sheet1")
- crr = d(aa)(0)
- .Range("c2") = crr(1)
- .Range("k2") = crr(2)
- .Range("o2") = crr(3)
- .Range("t2") = crr(4)
- .Range("y2") = crr(5)
- .Range("ae2") = crr(6)
- For i = 4 To 92 Step 8
- .Cells(i, 3).Resize(7, 32).ClearContents
- Next
- For Each bb In d(aa).keys
- If bb <> 0 Then
- brr = d(aa)(bb)
- .Cells(bb * 8 - 4, 3).Resize(UBound(brr), UBound(brr, 2)) = brr
- End If
- Next
- .Copy
- With ActiveWorkbook
- .SaveAs Filename:=ThisWorkbook.Path & "" & aa
- .Close False
- End With
- End With
- Next
-
- End Sub
复制代码 |
|