PDA

View Full Version : VBA Print Range



dpmaki
06-08-2012, 07:27 AM
I want to define a print range in a worksheet printing from column A through Y and the end of column K defines the last row.

Is there a way to do this through VBA? This is what I've come up with so far.

Sub PrintRangeUS()

Dim FinalRow As Long

Sheets("US Upload").Select
FinalRow = Cells(Rows.Count, "K").End(xlUp).Row

VoG
06-08-2012, 07:30 AM
Try



Sub PrintRangeUS()

Dim FinalRow As Long

Sheets("US Upload").Select
FinalRow = Cells(Rows.Count, "K").End(xlUp).Row
ActiveSheet.PageSetup.PrintArea = "A1:Y" & FinalRow

CodeNinja
06-08-2012, 07:33 AM
Try Sheets(sheetname).PageSetup.PrintArea = Area to print

Lol, you beat me to it VoG

dpmaki
06-08-2012, 07:54 AM
Nice. What if I wanted to also specify landscape and print 1st row on every page. Is that also possible to do?

VoG
06-08-2012, 08:00 AM
Try this



Sub PrintRangeUS()
Dim FinalRow As Long
Sheets("US Upload").Select
FinalRow = Cells(Rows.Count, "K").End(xlUp).Row
With ActiveSheet.PageSetup
.PrintArea = "A1:Y" & FinalRow
.Orientation = xlLandscape
.PrintTitleRows = "$1:$1"
End With

dpmaki
06-08-2012, 08:19 AM
I figured it out:

ActiveSheet.PageSetup.PrintArea = "A1:Y" & FinalRow
ActiveSheet.PageSetup.Orientation = xlLandscape
ActiveSheet.PageSetup.FitToPagesWide = 1
ActiveSheet.PageSetup.FitToPagesTall = 1000
ActiveSheet.PageSetup.PrintTitleRows = "$1:$1"

VoG
06-08-2012, 08:22 AM
You probably also need



Sub PrintRangeUS()
Dim FinalRow As Long
Sheets("US Upload").Select
FinalRow = Cells(Rows.Count, "K").End(xlUp).Row
With ActiveSheet.PageSetup
.PrintArea = "A1:Y" & FinalRow
.Orientation = xlLandscape
.PrintTitleRows = "$1:$1"
.FitToPagesWide = 1
.FitToPagesTall = 1000
.Zoom = False
End With