Set Print Area

Firesword

New Member
Joined
Oct 10, 2018
Messages
40
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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
49,410
Office Version
  1. 365
Platform
  1. Windows
Try this instead of that line

Rich (BB code):
Sheet11.PageSetup.PrintArea = "A1:D" & llLastRow
 

Firesword

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

Lol I was close.

Thanks for such a quick reply.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
49,410
Office Version
  1. 365
Platform
  1. Windows
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. :)
 

Firesword

New Member
Joined
Oct 10, 2018
Messages
40
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Forum statistics

Threads
1,136,274
Messages
5,674,770
Members
419,525
Latest member
helensesc

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