|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Public d As Object
- Public d1 As Object
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- Dim d2 As New Dictionary
- With Worksheets("期初余额")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a1:c" & r)
- For i = 1 To UBound(arr)
- d1(arr(i, 1)) = Array(arr(i, 2), arr(i, 3))
- Next
- End With
- With Worksheets("凭证明细表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:j" & r)
- For i = 1 To UBound(arr)
- If Not d.Exists(arr(i, 1)) Then
- m = 1
- ReDim brr(1 To 8, 1 To m)
- Else
- brr = d(arr(i, 1))
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 8, 1 To m)
- End If
- For j = 5 To 10
- brr(j - 4, m) = arr(i, j)
- Next
- d(arr(i, 1)) = brr
- Next
- End With
- For Each aa In d.Keys
- arr = d(aa)
- ReDim brr(0 To UBound(arr, 2), 1 To UBound(arr))
- If d1.Exists(aa) Then
- brr(0, 8) = d1(aa)(1)
- End If
- For i = 1 To UBound(arr)
- For j = 1 To UBound(arr, 2)
- brr(j, i) = arr(i, j)
- Next
- Next
- For i = 1 To UBound(brr)
- brr(i, 8) = brr(i - 1, 8) + brr(i, 5) - brr(i, 6)
- d2(brr(i, 1)) = ""
- Next
- ReDim crr(0 To UBound(brr) + d2.Count * 2, 1 To UBound(brr, 2))
- For i = 0 To 1
- For j = 1 To UBound(brr, 2)
- crr(i, j) = brr(i, j)
- Next
- Next
- m = 1
- y1 = brr(1, 5)
- y2 = brr(1, 6)
- n1 = brr(1, 5)
- n2 = brr(1, 6)
- For i = 2 To UBound(brr)
- If brr(i, 1) <> brr(i - 1, 1) Then
- m = m + 1
- crr(m, 4) = "本月合计"
- crr(m, 5) = y1
- crr(m, 6) = y2
- m = m + 1
- crr(m, 4) = "本年合计"
- crr(m, 5) = n1
- crr(m, 6) = n2
- y1 = 0
- y2 = 0
- End If
- m = m + 1
- For j = 1 To UBound(brr, 2)
- crr(m, j) = brr(i, j)
- Next
- y1 = y1 + brr(i, 5)
- y2 = y2 + brr(i, 6)
- n1 = n1 + brr(i, 5)
- n2 = n2 + brr(i, 6)
- Next
- m = m + 1
- crr(m, 4) = "本月合计"
- crr(m, 5) = y1
- crr(m, 6) = y2
- m = m + 1
- crr(m, 4) = "本年合计"
- crr(m, 5) = n1
- crr(m, 6) = n2
- y1 = 0
- y2 = 0
- d(aa) = crr
- Next
- End Sub
复制代码 |
|