Print selection, based on variable range of rows.

drjpb

Board Regular
Joined
Dec 11, 2013
Messages
66
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi,
I am unable to write a macro to print a sheet consisting of variable rows.

The sheet (SheetX) i want to print consists of 500 rows containing formulas (cells are linked to another sheet (SheetY) in same workbook).
So if SheetY have only 350 rows, i want the macro to print the range (A1:C350) in SheetX.

I believe i have to use the Count function in SheetY to specify the number of rows in SheetX, which then will be used in a macro.Thanking you in advance.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Code:
lr = Sheets("SheetY").UsedRange.Rows.Count
Set the PrintRange to
Code:
Range("A1:C" & lr)
 
Upvote 1
You need to add .Address to the end as PrintArea uses a String not a range i.e.


Code:
lr = Sheets("SheetY").UsedRange.Rows.Count
Sheets("SheetX").PageSetup.PrintArea = Sheets("SheetX").Range("A1:C" & lr).Address
 
Upvote 0
Solution

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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