|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
'先猜一个
Option Explicit
Sub test()
Dim i, j, k, kk, n, arr, sum
With Sheets("原表")
arr = .Range("a8:c" & .Cells(Rows.Count, "a").End(xlUp).Row + 1)
ReDim brr(1 To Rows.Count, 1 To UBound(arr, 2))
For i = 1 To UBound(arr, 1) - 1
For j = i To UBound(arr, 1) - 1
If arr(j, 1) <> arr(j + 1, 1) Then
n = n + 1: sum = 0
brr(n, 2) = arr(i, 1) & "明细表"
For k = i To j
n = n + 1: sum = sum + arr(k, 3)
For kk = 1 To UBound(arr, 2): brr(n, kk) = arr(k, kk): Next
Next
n = n + 1: brr(n, 2) = "合计:": brr(n, 3) = sum
n = n + 3: i = j: Exit For
End If
Next j, i
With .[f8] '输出位置自己修改
.Resize(Rows.Count - 7, UBound(brr, 2)).ClearContents
.Offset(-1).Resize(, 3) = Split("科目 代码 金额")
If n > 0 Then .Resize(n, UBound(brr, 2)) = brr
End With
End With
End Sub |
评分
-
1
查看全部评分
-
|