print only highlighted area

i am looking for two macros one that will print only the highlighted area and one that will print the entire  area.thanks
PRINT-ONLY.xlsb
SvgmassiveAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
MacroShadowConnect With a Mentor Commented:
The only way is to copy the desired range to a new sheet then set the print area of the new sheet.
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
You should be able to record two macros for that purpose, each selecting the areas to print and then call the printing menu. This always gives you a  good start for writing VBA code. Usually you have to cleanup and improve the code somwhat.
0
 
MacroShadowCommented:
This sets the Printable Area to the highlighted cells:
Worksheets("Sheet1").PageSetup.PrintArea = Union("$C$1:$P$19", "$C$38:$P$51")

Open in new window


This will set the Printable Area to the entire bordered area:
Worksheets("Sheet1").PageSetup.PrintArea = "$C$1:$P$51"

Open in new window


If the highlighted and bordered ranges are dynamic, you will have to loop thru the range testing for the conditions and when met add them to the .PrintArea using the Union function.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The above code only sets the print area (as the name says). You will still have to call the printing after that with WorkSheets("Sheet1").PrintOut
0
 
SvgmassiveAuthor Commented:
macro shadow the union created a second page,Everything should fit on one page. thanks
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
You can set all of the print layout features using the PageSetup member of sheets; you'll have to set two properties here:
with Worksheets("Sheet1").PageSetup
  .PrintArea = Union("$C$1:$P$19", "$C$38:$P$51")
  .FitToPagesTall = 1
  .FitToPagesWide = 1
end with

Open in new window

This scales the printable area into a single page.
You can set the same whether you need gridlines, header/footer and so on, just see the VBA help for PageSetup.
0
 
SvgmassiveAuthor Commented:
can you attach a demo file?
0
 
Rob HensonFinance AnalystCommented:
In the Print dialogue, there is an option to Print only selected area. By default if this is not selected, the print range will be the whole sheet.

You could automate the selection of the Selected Area option with a VBA button but whats the point when there is already that option in the Standard print options?

Thanks
Rob H
0
 
SvgmassiveAuthor Commented:
i guess my next option would be to hide/show the rows
0
 
Rob HensonFinance AnalystCommented:
Did you look at the options in the Print setup? From your description, this does what you want.
0
 
SvgmassiveAuthor Commented:
i tried them
0
 
Martin LissOlder than dirtCommented:
I've requested that this question be closed as follows:

Accepted answer: 250 points for MacroShadow's comment #a40025671
Assisted answer: 250 points for Qlemo's comment #a40025679

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.