Set Print Area

Firesword

New Member
Joined
Oct 10, 2018
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Hi All

I need some help in setting the print area on a worksheet that is not the active sheet.

I have a data sheet (sheet10) where the user is putting in all the data that will be used to print off a form which is sheet11 (I use the code name in case the user changes the name). The data is variable.

VBA Code:
Sheet11.PageSetup.PrintArea = Sheet11.Range(Cells(1, "A"), Cells(llLastRow, "D")).Address

The code above works if i'm on sheet11, but will not work when I'm on sheet10, do I have to goto sheet11 (which I try not to do) then run the code or is there a way to set this from sheet 10?

Thanks

Simon
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try this instead of that line

Rich (BB code):
Sheet11.PageSetup.PrintArea = "A1:D" & llLastRow
 
Upvote 0
You're welcome.

Your code would have worked if you had prefaced every range with the sheet, like this

VBA Code:
Sheet11.PageSetup.PrintArea = Sheet11.Range(Sheet11.Cells(1, "A"), Sheet11.Cells(llLastRow, "D")).Address

But of course the direct text is simpler. :)
 
Upvote 0
You're welcome.

Your code would have worked if you had prefaced every range with the sheet, like this

VBA Code:
Sheet11.PageSetup.PrintArea = Sheet11.Range(Sheet11.Cells(1, "A"), Sheet11.Cells(llLastRow, "D")).Address

But of course the direct text is simpler. :)

I missed that (I need to kick myself I knew that). I'm sorry to have troubled you, I've also made a note about your code too.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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