ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   how macro or vba to print (https://www.excelbanter.com/excel-discussion-misc-queries/176624-how-macro-vba-print.html)

dlb1228

how macro or vba to print
 
i have an excel sheet that gets filled in with different data every week, one
week there are 20 rows the next week it maybe 11, is there a way to create a
macro or that only prints the range that i need each week

Don Guillett

how macro or vba to print
 
use a defined range name that is self adjusting to set your print area.
insertnamedefinename it something like myprintareain the refers to box
=offset($a$1,0,0,counta($a:$a),8)
look in the help index for OFFSET for more info

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"dlb1228" wrote in message
...
i have an excel sheet that gets filled in with different data every week,
one
week there are 20 rows the next week it maybe 11, is there a way to create
a
macro or that only prints the range that i need each week



E.Q.

how macro or vba to print
 
One option might be to record a macro. Start recording
(ToolsMacroRecordNewMacro). Place the cursor in the upper left cell where
you're certain that you'll have data for each report. select the current area
by Ctrl-Shift-8 then set the print area using the file menu option.
I made a mock sheet with data in cells b2 through c15 and recorded a macro.
The macro recorder gave me:
Range("B2").Select
Selection.CurrentRegion.Select
ActiveSheet.PageSetup.PrintArea = "$B$2:$C$15"
This will work as long as your print area doesn't have blank rows or columns
such that Excel won't recognize it as the "CurrentRegion".
Hope this helps.
Peace.
EQC

E.Q.

how macro or vba to print
 

My apologies, I just realized after posting that my method will always
reference the same print range since the macro recorder picked the absolute
address of the current range.
Please follow Don's advice...


All times are GMT +1. The time now is 09:53 PM.

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