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

Occasional Visitor

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


Here is a macro:

Sub InsertPageBreaks()
    Dim r As Long
    Dim m As Long
    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