Print Area and Printing

ASH2012

New Member
Joined
May 22, 2012
Messages
6
Hi All,

I want to set a conditional print area via a macro run from a button and print<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>


<o:p></o:p>
  • <LI style="mso-list: l0 level1 lfo1" class=MsoNormal>It is to print in the <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:eek:ffice:smarttags" /><st1:place w:st="on"><st1:PlaceType w:st="on">Range</st1:PlaceType> of <st1:PlaceName w:st="on">A3</st1:PlaceName></st1:place>:P800<o:p></o:p> <LI style="mso-list: l0 level1 lfo1" class=MsoNormal>It is only to print a line when an entry has been made in Column A<o:p></o:p> <LI style="mso-list: l0 level1 lfo1" class=MsoNormal>The print button activates the print window where they can say okay or select their printer<o:p></o:p>
  • When it does print it should be in landscape and made to fit by ‘x‘ amount tall by 1 wide<o:p></o:p>
<o:p></o:p>
Hope you can help J<o:p></o:p>
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I believe this will work:
Code:
Option Explicit

Sub ConditionalPrint()
    With ActiveSheet
        If .Cells(.Rows.Count, 1).End(xlUp).Row = 1 And Trim(.Range("A1").Value) = 0 Then GoTo End_Sub
        With .PageSetup
            .PrintArea = "$A$3:$P$800"
            .FitToPagesWide = 1
            .FitToPagesTall = False
        End With
    End With
    Application.Dialogs(xlDialogPrint).Show
End_Sub:
End Sub
 
Upvote 0
Hi,

Thanks for the response,

I have put the coding in and run it, I'm probably missing something, but when I preview it's not 1 page wide and there are multiple blank lines and blank pages too.

Again thanks for your help it is much appreciated. :)
 
Upvote 0
By the way, Welcome to the Board!

Try this modified code:
Code:
Sub ConditionalPrint()
    With ActiveSheet
        If .Cells(.Rows.Count, 1).End(xlUp).Row = 1 And Trim(.Range("A1").Value) = 0 Then GoTo End_Sub
        With .PageSetup
            .PrintArea = "$A$3:$P$800"
            .Orientation = xlLandscape
            .Zoom = False 'Must be set to False or ".FitToPagesTall = False" is ignored
            .FitToPagesWide = 1
            .FitToPagesTall = False
        End With
    End With
    Application.Dialogs(xlDialogPrint).Show
End_Sub:
End Sub

.Zoom = False should ensure a single page across.
The code in my initial response neglected the Landscape requirement. I have corrected it with this code.

As far as blank lines and pages, when you define a print area, all of that area is printed, even if it is blank. If you want to avoid blank lines between row 3 and 800 (you will have to either (manually or via code) find them and hide them. If you want to avoid blank lines/pages after the last populated row, you can either find and hide them or find the last populated row and adjust the $P$800 to reflect the last populated row.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top