• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Print Area-Fit to page

Thomas Kuriakose

Active Member
Dear Sirs,

The following code checked on the net is setting the print area with last row and last column, kindly correct me if I am wrong.

but I am not able to fit to page with A3 page size and landscape orientation.

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Range(Cells(Rows.Count, 1).End(xlUp)(2, 1), Cells(12, Columns.Count).End(xlToLeft)).Name = _
    "'" & ActiveSheet.Name & "'!Print_Area"
With ThisWorkbook.Worksheets("Sheet1").PageSetup
        .Zoom = False
        .FitToPagesTall = 1
        .FitToPagesWide = 1
    End With
End Sub

Kindly help with the correct code.

thanks,

with regards,
thomas
 

Attachments

  • Addtion and Subtraction of Columns based on cell input-3.xlsm
    36.8 KB · Views: 3
kindly correct me if I am wrong.
Code:
Range(Cells(Rows.Count, 1).End(xlUp)(2, 1), Cells(12, Columns.Count).End(xlToLeft)).Name = _
    "'" & ActiveSheet.Name & "'!Print_Area"

Should it be:
Code:
Range(Cells(Rows.Count, 1).End(xlUp)(2, 1), Cells(2, Columns.Count).End(xlToLeft)).Name = _
    "'" & ActiveSheet.Name & "'!Print_Area"
 
Dear Sir,

Thank you very much for this correction. Kindly also let me know the correct code for fit to page 1.

Thank you so much,

with regards,
thomas
 
Works here. Try the attached.
 

Attachments

  • chandoo24831Addtion and Subtraction of Columns based on cell input-3.xlsm
    34.8 KB · Views: 4
Dear Sirs,

I tried and this is not working at my end.

Is my code correct, doe we need to add the page size in the code and do we need the fit to page option in the code.

kindly check and confirm.

thanks,

with regards,
thomas
 
Dear Sirs,

I could not find anything more than these codes. I have tried again, but the print preview shows 1 of 7 pages.

The page setup required is -

Oiientation: Landscape
Size : A3
Fit to page as the number of columns keep varying with each project.

Thank you so much,

with regards,
thomaA
 
Sounds like the part that's missing is forcing the landscape and A3 paper setup? If so, change the macro in ThisWorkbook module to this
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Range(Cells(Rows.Count, 1).End(xlUp)(2, 1), Cells(2, Columns.Count).End(xlToLeft)).Name = "'" & ActiveSheet.Name & "'!Print_Area"
With ThisWorkbook.Worksheets("Sheet1").PageSetup
    .Zoom = False
    .FitToPagesTall = 1
    .FitToPagesWide = 1
    .Orientation = xlLandscape
    .PaperSize = xlPaperA3
End With
End Sub
 
Dear Sir,

Thank you for the solution, but I am still getting 1 of 7 pages in the preview.

Kindly fin attached the workbook.

Thank you so much,

with regards,
thomas
 

Attachments

  • Addtion and Subtraction of Columns based on cell input-3.xlsm
    34.1 KB · Views: 4
Back
Top