|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim rng As Range
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("对账单")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- Set rng = .Rows(r + 1)
- For i = 10 To r - 3
- If Not IsDate(.Cells(i, 1).Value) Then
- Set rng = Union(rng, .Rows(i))
- End If
- Next
- rng.Delete
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a10:s" & r - 3)
- For i = 1 To UBound(arr)
- For j = 1 To 9 Step 8
- xm = arr(i, j + 2) & "+" & arr(i, j + 3)
- If Not d.exists(xm) Then
- ReDim brr(1 To UBound(arr, 2))
- brr(1) = "合计"
- Else
- brr = d(xm)
- End If
- brr(j + 2) = arr(i, j + 2)
- brr(j + 3) = arr(i, j + 3)
- brr(j + 4) = brr(j + 4) + arr(i, j + 4)
- d(xm) = brr
- Next
- Next
- ReDim crr(1 To d.Count, 1 To UBound(brr))
- m = 0
- For Each aa In d.keys
- brr = d(aa)
- brr(18) = brr(5) - brr(13)
- m = m + 1
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- Next
- If m > 0 Then
- .Rows(r - 2).Resize(1 + UBound(crr)).Insert
- .Cells(r - 1, 1).Resize(UBound(crr), UBound(crr, 2)) = crr
- End If
- End With
- End Sub
复制代码 |
|