|
- Sub test()
- Dim r%, i%
- Dim arr, brr, zrr()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- With Worksheets("账单")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- .Range("k5:k" & r).UnMerge
- arr = .Range("a1:k" & r)
- xm = Empty
- m = 0
- For i = 5 To UBound(arr)
- If arr(i, 10) <> xm Then
- m = m + 1
- ReDim Preserve zrr(1 To m)
- zrr(m) = Array(i, i)
- xm = arr(i, 10)
- Else
- If m > 0 Then
- zrr(m)(1) = i
- End If
- End If
- Next
- For i = 1 To UBound(zrr)
- s = 0
- For j = zrr(i)(0) To zrr(i)(1)
- s = s + arr(j, 9) - arr(j, 7)
- Next
- With .Range(.Cells(zrr(i)(0), 11), .Cells(zrr(i)(1), 11))
- .Merge
- .Value = s
- End With
- Next
- End With
- End Sub
复制代码 |
|