Set print range in VB macro

Copper Contributor

I need to set the print range within a VB for a table that has variable length from run to run. The table is made up of the sum of multiple subtotals, all of which change from run to tun. That only means that I don't know the last cell address until the table is assembles. How can I define the range for this variable size?

7 Replies

@Ron_P88 

In VBA a simple print preview to build yourself. It can be set up as a module, as in the inserted workbook, or in any worksheet alone.
 
 
 

If you find this helpful, please mark it as "Best Answer" and as Like (click thumbs up), it will be beneficial to more Community members reading here.

 

Nikolino

I know I don't know anything (Socrates)

@NikolinoDE 

 

Sorry, but I don't see how this helps me. Perhaps I wasn't clear enough in describing my goal? I want to program the Set Print Range into my macro so I can print a variable range without human intervention. So far I have not found any way to use a variable to set the lower bound of the print range. The example in your post appears to have a fixed address in the print range specification (A1:AH60) although thi9s doesn't appear to be the range displayed when the Print Preview button is selected. What am I missing?

@Ron_P88 

 

Tailored to your area.

If other area is desired or the whole worksheet it can be changed by VBA.

Hope this worksheet meets your needs. If not please give a short feedback.
 
Sorry but when I execute your sub on my file before a print range is set I get a 4 page display of the entire worksheet rather than the y2:AD312 range that this week's data calls for. Another week with different data would call for a range of y2 to some other lower bound.
You have to determine in advance which area you want to print, if the lines in this area are empty should not be printed or hidden, this means selecting a large printing area in advance depending on the data that can occur ... is this correct?... what I have expressed.

@Ron_P88 

 

Maybe this approach will help you.

Thank you for your continued support of my problem. I apologize for not responding sooner but other unrelated events have taken up my time. Your latest example looks promising and I will have to work with it to fit my case.

 

Viele Dank!

 

Ron