Setting the print area using a variable in VBA

kmh6278

Board Regular
Joined
Mar 7, 2006
Messages
52
I'm looping through a number of reports, and the print area is going to vary, depending on how many columns of data I have present. The starting cell will always be A1, but sometimes the print area will end at D1, E1, F1, etc.

Is there a way to use VBA to set the print area for each report, by refering to a worksheet containing the correct # of columns of data present.

In worksheet "Count," cell A1 = 3. This would mean the print area of my report would be A1 to (A1+3).
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub PRT()
ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.Address
ActiveSheet.PrintOut
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,377
Messages
5,836,914
Members
430,462
Latest member
djkiwi1

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
Top