I have the following Code Below. The 1st page break should be row 49, but the break sows at row 44.
It would be appreciated if someone could amend my code so that 1st break is at row 49 and 2nd break to be up to last row containing data
It would be appreciated if someone could amend my code so that 1st break is at row 49 and 2nd break to be up to last row containing data
Code:
Sub Print_Preview()
Dim ws As Worksheet
Dim lastRow As Long
Dim lastCol As Long
Dim printRange As Range
Set ws = Sheets("Summary")
With ws
' Find the last row and column containing data
lastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
lastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
' Define the print range starting from Column F to the last column
Set printRange = .Range(.Cells(1, "F"), .Cells(lastRow, lastCol))
' Set up the page setup options
With .PageSetup
.PrintTitleRows = "$1:$1" ' Row 1 repeats at top
.PrintTitleColumns = "$A:$A" ' Column A repeats on each page
.Orientation = xlLandscape
.Zoom = False ' Turn off automatic zoom
.FitToPagesWide = 2 ' Fit to 1 page wide
.FitToPagesTall = 2 ' Fit to 2 pages tall (70% scale)
.PrintGridlines = True
' Headers and footers
.LeftHeader = "&D&T"
.CenterHeader = "Turnover Data"
.RightHeader = "Page &P of &N"
End With
' Reset all existing page breaks
.ResetAllPageBreaks
' Insert a manual horizontal page break at row 49
.HPageBreaks.Add Before:=.Cells(53, "F")
' Activate the sheet and display Page Break Preview
.Activate
ActiveWindow.View = xlPageBreakPreview
' Set the print area for the defined range
.PageSetup.PrintArea = printRange.Address
' Show Print Preview
printRange.PrintPreview
End With
End Sub [code]