ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to define a print range? (https://www.excelbanter.com/excel-programming/287034-how-define-print-range.html)

TinyTim

How to define a print range?
 

I have a worksheet that a user enters data starting at "A7". For each
input row he fills columns "A" thru "G". He then presses a
commandbutton to calculate columns "I" thru "N" for each entry.

I clear the area A7:BB500, knowing there won't be more than 150 rows
at any one time. Now I'm planning to provide a commandbutton to print
the keyed-in data and calculated results. If the user only enters say
15 rows of data, does the calculation and goes to print. It prints
many blank pages after the data. I'm assuming the print settings say
to print thru range BB500 or at least BBxx. (xx=last row)

How do I get only the entire range of data entered/calced (a7:n22) to
be printed? Please show in code.

Starting range is "A7". Ending row is retrieved using "xlup". I know
last column to be printed is "N".

Dim StartRange as Range
Dim LastRow as Long
Dim LastCol as String

LastCol = "N"
Set StartRange = Range("A7")
LastRow = ActiveSheet.Cells(65535, 3).End(xlUp).Row

Now, how do I assemble all this information and place into the print
area range?????


tt


david mcritchie

How to define a print range?
 
The following will probably solve your problem without any need
to set the print area. Usually if you have to set the print area
you have something wrong.

dim xlong as long
xlong = ActiveSheet.UsedRange.Rows.Count 'correct lastcell

More information in
Automatically Resetting the Last Cell in Excel 97, Tip 73, John Walkenbach.
Activesheet.UsedRange has also been suggested.
http://www.j-walk.com/ss/excel/tips/tip73.htm

Reset Last Used Cell
http://www.mvps.org/dmcritchie/excel/lastcell.htm

look in Excel VBA help for printarea

--
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"TinyTim" wrote in message ...

I have a worksheet that a user enters data starting at "A7". For each
input row he fills columns "A" thru "G". He then presses a
commandbutton to calculate columns "I" thru "N" for each entry.

I clear the area A7:BB500, knowing there won't be more than 150 rows
at any one time. Now I'm planning to provide a commandbutton to print
the keyed-in data and calculated results. If the user only enters say
15 rows of data, does the calculation and goes to print. It prints
many blank pages after the data. I'm assuming the print settings say
to print thru range BB500 or at least BBxx. (xx=last row)

How do I get only the entire range of data entered/calced (a7:n22) to
be printed? Please show in code.

Starting range is "A7". Ending row is retrieved using "xlup". I know
last column to be printed is "N".

Dim StartRange as Range
Dim LastRow as Long
Dim LastCol as String

LastCol = "N"
Set StartRange = Range("A7")
LastRow = ActiveSheet.Cells(65535, 3).End(xlUp).Row

Now, how do I assemble all this information and place into the print
area range?????


tt





All times are GMT +1. The time now is 09:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com