|
- Sub test3()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("流水账")
- r = .Cells(.Rows.Count, 27).End(xlUp).Row
- arr = .Range("aa4:aj" & r)
- For i = 1 To UBound(arr)
- If Right(arr(i, 5), 1) <> "计" Then
- If Not d.exists(arr(i, 8)) Then
- Set d(arr(i, 8)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 8)).exists(arr(i, 1)) Then
- m = 1
- ReDim brr(1 To UBound(arr, 2), 1 To m)
- Else
- brr = d(arr(i, 8))(arr(i, 1))
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To UBound(arr, 2), 1 To m)
- End If
- For j = 1 To UBound(arr, 2)
- brr(j, m) = arr(i, j)
- Next
- d(arr(i, 8))(arr(i, 1)) = brr
- End If
- Next
- .Range("aa4:aj" & r).ClearContents
- m = 4
- For Each aa In d.keys
- gs = ""
- For Each bb In d(aa).keys
- arr = d(aa)(bb)
- ReDim brr(1 To UBound(arr, 2), 1 To UBound(arr))
- For i = 1 To UBound(arr)
- For j = 1 To UBound(arr, 2)
- brr(j, i) = arr(i, j)
- Next
- Next
- .Cells(m, 27).Resize(UBound(brr), UBound(brr, 2)) = brr
- If bb <> 0 Then
- .Cells(m + UBound(brr), 31) = "本月合计"
- .Cells(m + UBound(brr), 32) = Split(aa, "-")(0)
- .Cells(m + UBound(brr), 33) = Split(aa, "-")(1)
- .Cells(m + UBound(brr), 34) = aa
- .Cells(m + UBound(brr), 35).Resize(1, 2).FormulaR1C1 = "=SUM(R" & m & "C:R[-1]C)"
- gs = gs & "+" & "R" & m + UBound(brr) & "C"
- .Cells(m + UBound(brr) + 1, 31) = "本年累计"
- .Cells(m + UBound(brr) + 1, 32) = Split(aa, "-")(0)
- .Cells(m + UBound(brr) + 1, 33) = Split(aa, "-")(1)
- .Cells(m + UBound(brr) + 1, 34) = aa
- .Cells(m + UBound(brr) + 1, 35).Resize(1, 2).FormulaR1C1 = "=" & Mid(gs, 2)
- m = m + UBound(brr) + 2
- Else
- m = m + UBound(brr)
- End If
- Next
- Next
- End With
- End Sub
复制代码 |
|