Print Question?

Todd_M

Board Regular
Joined
Feb 24, 2002
Messages
117
Hi-
I have a sheet that the user can print by clicking a commandbutton.


Range("A1:I160").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$I$160"
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintComments = xlPrintNoComments
.PrintQuality = -3
.Orientation = xlLandscape
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver

End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
end sub

I set the rows to be printed to row 160. My question is if there is only data to fill one page (up to row 35) and the rest of the print range contains empty cells, how do you write a code that will stop the printer from printing the last blank 4 sheets. This sheet im printing at times may contain 10 rows of data or 150 rows of data at anytime.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Is the data that you want to print the only data on the worksheet?

If it is then you could replace:
<pre>
Range("A1:I160").Select </pre>

With
<pre>
Activesheet.UsedRange.Select</pre>

HTH
 
Upvote 0
Thanks Mark, sorry it to so long to respond. The Activesheet.UsedRange.Select works fine, however in column M, I have text that goes down to Row 180, and when I apply this code the selection highlights range A1:M180. I only want the usedrange.selection to set a print area for any used cells in rangeA1:I160, then print out only as many pages as needed.
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,478
Members
448,967
Latest member
visheshkotha

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