本文介绍了试图创建分页符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试在每20行后创建分页符,减去顶行(标题) 但我不确定如何修复代码。这只是我在条件pg中断时发现的,并且还没有为群组设置它。   ; Dim CellRange作为范围 Dim TestCell As Range ActiveSheet.ResetAllPageBreaks 设置CellRange =选择 适用于CellRange中的每个TestCell 如果TestCell.Value<> TestCell.Offset(-1,0).Value然后 ActiveSheet.Rows(TestCell.Row).PageBreak = xlPageBreakManual 结束如果是 Next TestCell End Sub 解决方案 你可以使用这个函数 这里For循环从21开始,因为你提到了第一个分页应该是20 + 1(标题)。你可以调整它。在"步骤"之后提到的数字20。那是间隔。您可以根据自己的需要进行调整。 Sub PageBreakAfter20() Dim totalRange As Range ActiveSheet.ResetAllPageBreaks Set totalRange = ActiveSheet.UsedRange for irow = 21 To totalRange.Rows.Count Step 20 Rows(irow)。 PageBreak = xlPageBreakManual 下一个结束子 I'm trying to create page breaks after every 20 rows, minus the top row (headers) but I'm not sure how to fix the code. This is just something I found on conditional pg breaks, and haven't set it for groups yet. Dim CellRange As Range Dim TestCell As Range ActiveSheet.ResetAllPageBreaks Set CellRange = Selection For Each TestCell In CellRange If TestCell.Value <> TestCell.Offset(-1, 0).Value Then ActiveSheet.Rows(TestCell.Row).PageBreak = xlPageBreakManual End If Next TestCellEnd Sub 解决方案 Hi,You can use this function Here For loop is starting from 21 because you mentioned the first page break should be 20+1 (header). This you can adjust it. The number 20 which is mentioned after "Step" that is the interval. You can adjust that as well as per youir need.Sub PageBreakAfter20() Dim totalRange As Range ActiveSheet.ResetAllPageBreaks Set totalRange = ActiveSheet.UsedRange For irow = 21 To totalRange.Rows.Count Step 20 Rows(irow).PageBreak = xlPageBreakManual NextEnd Sub 这篇关于试图创建分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-23 09:51