kmmsquared
New Member
- Joined
- Jan 7, 2011
- Messages
- 33
Hi,
I am using the following code to set print ranges. I use this same exact code as part of another macro and it formats the pages correctly (it only uses the number of pages tall that is necessary). In a separate workbook, the columns format correctly in width, but there are extra pages added after the last row of data. For example when the spreadsheet print range should be 55 pages long, output is 290 pages--just blank pages (except for the repeated row 1) after page 55.
How can I fix this? Any help would be appreciated! Thanks!
I am using the following code to set print ranges. I use this same exact code as part of another macro and it formats the pages correctly (it only uses the number of pages tall that is necessary). In a separate workbook, the columns format correctly in width, but there are extra pages added after the last row of data. For example when the spreadsheet print range should be 55 pages long, output is 290 pages--just blank pages (except for the repeated row 1) after page 55.
How can I fix this? Any help would be appreciated! Thanks!
Code:
Sub PageSetup()
Dim LastRow As Long
Dim LastColumn As Long
With Sheets("B")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastColumn = Application.WorksheetFunction.Match("E", Range("1:1"), 0)
Sheets("B").Select
Sheets("B").Activate
With ActiveSheet.PageSetup
.FirstPageNumber = 1
.PrintTitleRows = "$1:$1"
.PaperSize = xlPaperLegal
.Orientation = xlLandscape
.Zoom = False
.View = xlPageBreakPreview
[COLOR=red].FitToPagesWide = 1
.FitToPagesTall = 1000
[/COLOR].PrintArea = "A1:" & LastColumn & LastRow
End With
End Sub