Inserting a Page Break Every X Rows

Written by Allen Wyatt (last updated February 25, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


Maria has a worksheet in which she wants to start a new page after every X number of rows. This break is not dependent on any data in the worksheet, simply on the number of rows. (For instance, she may want to start a new page after every 17 rows.) Maria wonders if there is a way to insert a repeating page break that is solely dependent on the number of rows.

There is no way to do this through a setting or through any conditional formatting. The only way we've been able to accomplish this is through the use of a macro. The following macro provides a bit of interaction to increase its flexibility.

Sub BreakEveryX()
    Dim iGap As Integer
    Dim lLastRow As Long
    Dim lRow As Long
    Dim sTitle As String
    Dim bGo As Boolean
    Dim sTemp As String

    sTitle = "Set Page Breaks"
    bGo = True

    sTemp = InputBox("Enter rows per page:", sTitle)
    iGap = Val(sTemp)
    If iGap > 0 Then
        sTemp = InputBox("Last row for page breaks:", sTitle)
        lLastRow = Val(sTemp)
        If lLastRow >= iGap Then
            With ActiveSheet
                .ResetAllPageBreaks
                For lRow = iGap + 1 To lLastRow Step iGap
                    .HPageBreaks.Add Before:=.Cells(lRow, 1)
                Next lRow
            End With
        Else
            bGo = False
        End If
    Else
        bGo = False
    End If

    If Not bGo Then
        MsgBox Prompt:="No changes made", Title:=sTitle
    End If
End Sub

All you need to do is to display the worksheet you want to affect, and then run the macro. You are asked for how many rows you want per page (for Maria's example, that might be 17) and the row you want to stop at. The macro then removes all existing page breaks and inserts a page break after each multiple of the per-page rows you specified. If you enter 0 for the rows per page or if the ending row number is less than the rows per page, then no changes are made and you see a message box to that effect.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13023) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Collecting Highlighted Text Selections

Got a document with text passages marked with the highlighter tool? You can collect all those highlighted selections and ...

Discover More

Problems with Default Workbook and Worksheet Templates

You can create a default template for both your workbooks and worksheets. These should be placed in the xlstart folder, ...

Discover More

Determining if Caps Lock is On

If your macro needs to determine the status of the Caps Lock key, you need the code in this tip. Just use the Information ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Workbook Events

You can create macros that run whenever Excel detects a certain event happening within an entire workbook. This tip ...

Discover More

Calling a Subroutine from a UDF

Excel allows you to create a special type of macro called a user-defined function (UDF). These can let you add to the ...

Discover More

Copying a Set Range from Multiple Worksheets to a New Worksheet

Want to create a summary worksheet that pulls a single row of data from each worksheet in the workbook? Here are a couple ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 1 + 1?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.