Archive of Mr Excel Message Board


Back to Printing in Excel archive index
Back to archive home

Code to stop print loop at 1st blank cell

Posted by Gregg on March 03, 2001 8:16 AM
Would appreciate some help with macro code. Have macro to print all 250 rows on spreadsheet, but sometimes I only need to print 25 rows. I would like to temporarily clear a cell (i.e., row 26) so that the print macro would stop at row 25. Hope this is as easy as it sounds, but I am new to macros so I haven't been able to figure it out.
Thanks in advance,
Gregg

Re: Code to stop print loop at 1st blank cell

Posted by Roger Redhat on March 04, 2001 11:52 AM

If you use this code it will set the print area to A1:F & whatever row contains a blank cell in column A.

Rog.


Sub PrintMacro()
Dim r As Integer, NumberOfColumns As Integer
Dim PrintRange As Range
'Determine print range
r = 0
Do Until Cells(r + 1, 1).Value = ""
r = r + 1
Loop


NumberOfColumns = 6 'Change this depending on how many
'columns you want printed.

Set PrintRange = ActiveSheet.Range(Cells(1, 1), Cells(r, NumberOfColumns))
With ActiveSheet.PageSetup
.PrintArea = PrintRange.Address
.FitToPagesTall = 1
.FitToPagesWide = 1
End With

ActiveSheet.PrintOut
End Sub


Roger - Thanks & A Tip of the hat to you!

Posted by Gregg on March 04, 2001 12:39 PM
It did the trick!!
Gregg

This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.