Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim rngToPrint As Range, rngLast As Range
With ThisWorkbook.Worksheets("DVD Lijssie") ' EDIT with YOUR own Sheet name !!! !!! !!!
.Activate
Set rngLast = LastCell
'establish last cell
Set rngToPrint = Range(Range("A1"), rngLast)
'set the actual print area required
End With
ActiveSheet.PageSetup.PrintArea = rngToPrint.Address
'NB use address to return A1 style
Set rngLast = Nothing
Set rngToPrint = Nothing
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$3"
End With
ActiveSheet.PrintPreview EnableChanges:=False ' Disable changes in PlotPreview
With ActiveSheet.PageSetup
.CenterHorizontally = True
.CenterVertically = False
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
End With
End Sub
Function LastCell() As Range
Dim LastColumn As Integer
Dim LastRow As Long
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'Search for any entry, by searching backwards by Columns.
LastColumn = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
End If
Set LastCell = Cells(LastRow, LastColumn)
End Function