Forum Discussion

MLAcapgroupcom's avatar
MLAcapgroupcom
Copper Contributor
May 05, 2021

How do I insert a page break every 5th row? marco?

I have a 698 line Excel file that I need separated at every 5th line.  How do I create a marco to accomplish this or is there a way to do this by using the insert page break option?  I'm using Excel for Office 365

1 Reply

  • MLAcapgroupcom 

    Here is a macro:

    Sub InsertPageBreaks()
        Dim r As Long
        Dim m As Long
        ActiveSheet.ResetAllPageBreaks
        m = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Range("A" & m).Select
        For r = 6 To m Step 5
            ActiveSheet.HPageBreaks.Add Before:=Range("A" & r)
        Next r
    End Sub

Resources