ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to insert page break after every 10 rows? (https://www.excelbanter.com/excel-discussion-misc-queries/152524-how-insert-page-break-after-every-10-rows.html)

kativa

How to insert page break after every 10 rows?
 
Could anybody help me with the VBA-code needed ub this? I have 3000 rows in
one sheet and I would like to print only 10 rows for each paper.

Dave Peterson

How to insert page break after every 10 rows?
 
One way:

Option Explicit
Sub testme()
Dim myCell As Range
Dim iRow As Long
Dim LastRow As Long
Dim FirstRow As Long

With Worksheets("Sheet1")
FirstRow = 11
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

.ResetAllPageBreaks

For iRow = FirstRow To LastRow Step 10
.Cells(iRow, "A").PageBreak = xlPageBreakManual
Next iRow
End With
End Sub

I put the first pagebreak before row 11. I used column A to find out the last
used row.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

kativa wrote:

Could anybody help me with the VBA-code needed ub this? I have 3000 rows in
one sheet and I would like to print only 10 rows for each paper.


--

Dave Peterson

kativa

How to insert page break after every 10 rows?
 
Thank you very much! The way doesn't matter until the code works and this
did. You made my day :=)

-Kate

"Dave Peterson" kirjoitti:

One way:

Option Explicit
Sub testme()
Dim myCell As Range
Dim iRow As Long
Dim LastRow As Long
Dim FirstRow As Long

With Worksheets("Sheet1")
FirstRow = 11
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

.ResetAllPageBreaks

For iRow = FirstRow To LastRow Step 10
.Cells(iRow, "A").PageBreak = xlPageBreakManual
Next iRow
End With
End Sub

I put the first pagebreak before row 11. I used column A to find out the last
used row.

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

kativa wrote:

Could anybody help me with the VBA-code needed ub this? I have 3000 rows in
one sheet and I would like to print only 10 rows for each paper.


--

Dave Peterson



All times are GMT +1. The time now is 08:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com