|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("流水账")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:d" & r)
- End With
- For i = 1 To UBound(arr)
- nf = Year(arr(i, 3))
- yf = Month(arr(i, 3))
- If Not d.exists(arr(i, 1)) Then
- Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 1)).exists(arr(i, 2)) Then
- Set d(arr(i, 1))(arr(i, 2)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 1))(arr(i, 2)).exists(nf) Then
- Set d(arr(i, 1))(arr(i, 2))(nf) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 1))(arr(i, 2))(nf).exists(yf) Then
- ReDim brr(1 To 17)
- brr(1) = arr(i, 1)
- brr(2) = arr(i, 2)
- brr(3) = nf
- brr(4) = yf
- Else
- brr = d(arr(i, 1))(arr(i, 2))(nf)(yf)
- End If
- brr(5) = brr(5) + arr(i, 4)
- brr(yf + 5) = brr(yf + 5) + arr(i, 4)
- d(arr(i, 1))(arr(i, 2))(nf)(yf) = brr
- Next
- With Worksheets("统计")
- .UsedRange.Offset(1, 0).ClearContents
- m = 1
- For Each aa In d.keys
- For Each bb In d(aa).keys
- For Each cc In d(aa)(bb).keys
- For Each dd In d(aa)(bb)(cc).keys
- brr = d(aa)(bb)(cc)(dd)
- m = m + 1
- .Cells(m, 1).Resize(1, UBound(brr)) = brr
- Next
- Next
- Next
- Next
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("a1").Resize(r, UBound(brr)).Borders.LineStyle = xlContinuous
- End With
- End Sub
复制代码 |
|