kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Hi ,
Instead of hardcoding the number of rows to set the pagebreak into the script, I want to set that dynamically using some criteria:
In column B, I have say x, y, z, etc. they are sorted so all x before all y then all z etc. so I want to set the pagebreak to match the x items then the y items etc.
To put long story short, I wanna have each criteria on a page.
I need some assistance to resolve this.
Thanks
Kelly
Instead of hardcoding the number of rows to set the pagebreak into the script, I want to set that dynamically using some criteria:
In column B, I have say x, y, z, etc. they are sorted so all x before all y then all z etc. so I want to set the pagebreak to match the x items then the y items etc.
To put long story short, I wanna have each criteria on a page.
I need some assistance to resolve this.
Thanks
Kelly
Code:
Sub HPage_Breaks()
Dim rpp As Long, rh As Long, i As Long, lr As Long, lc As Long
lr = Sheet2.Cells.Find("*", , , , xlByRows, xlPrevious).Row
lc = Sheet2.Cells.Find("*", , , , xlByColumns, xlPrevious).Column
On Error GoTo Cancelled
ActiveWindow.View = xlPageBreakPreview
ActiveWindow.View = xlNormalView
With Sheet2
.ResetAllPageBreaks
.PageSetup.Zoom = 50
.PageSetup.PrintArea = .Range("A2:O" & lr).Address
.PageSetup.PrintTitleRows = "$1:$2"
.HPageBreaks.Add (.Cells(52, 1))
For i = 1 To lr / (51)
.HPageBreaks.Add (.Cells(.HPageBreaks(i).Location.Row + 51, 1))
Next i
End With
Sheet2.PrintOut
Cancelled:
Exit Sub
End Sub