Johnny Thunder
Well-known Member
- Joined
- Apr 9, 2010
- Messages
- 693
- Office Version
- 2016
- Platform
- MacOS
Hi guys,
Stuck on a code and can't seem to get it to work, hoping someone has come across this in the past or knows how to do this.
I have a Set Print Area script that loops thru sheet in a newly added workbook and sets print area and some formatting and I added a line that inserts a page break on row 66 but this doesn't seem to be working. Currently it is entering the line break on row 90.
Any help is appreciated.
Stuck on a code and can't seem to get it to work, hoping someone has come across this in the past or knows how to do this.
I have a Set Print Area script that loops thru sheet in a newly added workbook and sets print area and some formatting and I added a line that inserts a page break on row 66 but this doesn't seem to be working. Currently it is entering the line break on row 90.
Any help is appreciated.
Code:
Sub PrintArea()
Dim lr As Long
Dim ws As Worksheet, sht As Worksheet
Dim cL As Variant 'Finds Column Letter
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
Select Case ws.Name
Case "Lookups"
'For sheets you don't want affected by the macro create a case like the "lookups Sheet line
Case Else
With ws
cL = Split(ws.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Cells.Address(1, 0), "$")(0) 'Finds last column with Data
lr = .Range("B" & Rows.Count).End(xlUp).Row 'Finds last row with data
'Setup for the Print Area and Format of Margins
.PageSetup.PrintArea = .Range("B1:" & cL & lr).Address
.PageSetup.Zoom = False
.PageSetup.LeftMargin = Application.InchesToPoints(0.5)
.PageSetup.RightMargin = Application.InchesToPoints(0.5)
.PageSetup.TopMargin = Application.InchesToPoints(0.5)
.PageSetup.BottomMargin = Application.InchesToPoints(0.5)
.PageSetup.HeaderMargin = Application.InchesToPoints(0.2)
.PageSetup.FooterMargin = Application.InchesToPoints(0.2)
.PageSetup.FitToPagesWide = 1
.PageSetup.FitToPagesTall = 2
.PageSetup.Orientation = xlLandscape 'or xlPortrait
.ResetAllPageBreaks
.HPageBreaks.Add Before:=Rows(66) 'Page break line
End With
End Select
Next ws
End Sub
Last edited: