|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
插入人工分页符
Sub 插入小计合计()
Dim x, y%, r%, a%, b%, i%, n%, j%
Worksheets("工资表").Activate
x = InputBox("请输入每页拟打印的行数: (不能超过一页的范围!!!)")
r = Range("a65536").End(3).Row - 1
y = WorksheetFunction.RoundUp((r - 5) / x, 0)
For i = 1 To y
a = (i - 1) * 1 * x + 4 + i
If i = y Then
b = r + i - 1
Else
b = a + x - 1
End If
Rows(b + 1).Insert Shift:=xlDown 'B+1行之上插入一行
MsgBox b
If i = y Then
Rows(b).Copy Rows(b + 1)
Rows(b + 1).ClearContents
End If
Cells(b + 1, 1) = "本页小计"
ActiveSheet.HPageBreaks.Add Before:=Cells(b + 2, 1) ''插入人工分页符
For j = 4 To 20
Cells(b + 1, j).Value = Application.WorksheetFunction.Sum(Range(Cells(a, j), Cells(b, j)))
Next
If i = y Then
Rows(b + 2).Insert Shift:=xlDown 'B+2行之上插入一行
Rows(b).Copy Rows(b + 2)
Rows(b + 2).ClearContents
Cells(b + 2, 1) = "总 计"
ActiveSheet.HPageBreaks.Add Before:=Cells(b + 3, 1) ''插入人工分页符
For n = 5 To b + 1
For j = 4 To 20
If Cells(n, 1) = "本页小计" Then
Cells(b + 2, j) = Cells(b + 2, j) + Cells(n, j)
End If
Next
Next
End If
Next
End Sub
Sub 删除小计合计()
ActiveSheet.ResetAllPageBreaks ''删除人工分页符
r = Range("a65536").End(3).Row
For i = r To 5 Step -1
If Cells(i, 1) = "本页小计" Or Cells(i, 1) = "总 计" Then
Rows(i).Delete
End If
Next
End Sub |
评分
-
1
查看全部评分
-
|