Print a dynamic named range with VBA

Gerasimos_Zap

New Member
Joined
Sep 23, 2015
Messages
20
I have a report that I am trying to print with a VBA script. I need to print the report on one page (portrait) and have it centered. I have the formatting down pat, but the range is causing me issues. I need to set the print range to adjust to the number of values in the named range. Right now, it will print the named range, but it will not resize or print the new range if there have been entries added.

Code:
Sub PrintFailureReport()

Sheets("Failure Report").Activate
Range("FailReport").Select
ActiveSheet.PageSetup.PrintArea = Selection.Range("FailReport").Address
Application.PrintCommunication = True

With ActiveSheet.PageSetup
    .LeftMargin = Application.InchesToPoints(0.25)
    .RightMargin = Application.InchesToPoints(0.25)
    .TopMargin = Application.InchesToPoints(0.25)
    .BottomMargin = Application.InchesToPoints(0.25)
'    .HeaderMargin = Application.InchesToPoints(0.3)
'    .FooterMargin = Application.InchesToPoints(0.3)
    .PrintGridlines = False
    .CenterHorizontally = True
    .CenterVertically = True
    .Orientation = xlPortrait
    .PaperSize = xlPaperLetter
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    .BlackAndWhite = True
    
End With

Range("FailReport").PrintOut

End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,215,479
Messages
6,125,043
Members
449,206
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top