|
|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub ykcbf() '//2025.4.8 插入小计、插入累计
- Application.ScreenUpdating = False
- bt = 3: col = 2: c = 12: rr = 24: c1 = 7
- xm = [{"每页小计","每页累计"}]
- With ActiveSheet
- If .FilterMode = True Then .ShowAllData '//取消筛选状态
- r = .Cells(Rows.Count, 1).End(xlUp).Row
- m = r - bt
- If rr < 1 Then Exit Sub
- k = Application.Ceiling(m / rr, 1)
- For i = k To 1 Step -1
- r1 = bt + 1 + (i - 1) * rr
- r2 = Application.Min(r, bt + 1 + (i * rr - 1))
- m = r2 + 1
- .Rows(m & ":" & m + 1).Insert Shift:=xlDown
- .Cells(m, col).Value = xm(1)
- .Cells(m, 1).Resize(1, c).Interior.ColorIndex = 6
- .Cells(m, c1).Resize(, c - c1 + 1).Formula = "=SUM(" & Cells(r1, c1).Resize(r2 - r1 + 1).Address(1, 0) & ")"
- m = m + 1
- .Cells(m, col).Value = xm(2)
- .Cells(m, 1).Resize(1, c).Interior.ColorIndex = 4
- .Cells(m, c1).Resize(, c - c1 + 1).Formula = "=SUMIFS(" & Cells(bt + 1, c1).Resize(m - bt - 1).Address(1, 0) _
- & "," & Cells(bt + 1, col).Resize(m - bt - 1).Address & "," & """" & xm(1) & """" & ")"
- .Cells(r2 + 1, 8).Resize(2) = "": .Cells(r2 + 1, 10).Resize(2) = ""
- Next i
- r = .Cells(Rows.Count, col).End(3).Row
- .[a1].Resize(r, c).Borders.LineStyle = 1
- End With
- Application.ScreenUpdating = True
- MsgBox "插入完成!共处理:" & k & " 段,插入行数:" & k * 2
- End Sub
复制代码
|
|