VBA for page setup with dynamic number of pages tall

Iron_Man

New Member
Joined
Aug 26, 2014
Messages
25
Hi folks,

I found on this forum a fantastic piece of code to set the page setup of a particular sheet in my workbook.

Code:
Sub Print_Format()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With ActiveSheet.PageSetup
    .PrintTitleRows = "1:1"
    .PrintArea = "A1:I" & LR
    .LeftMargin = Application.InchesToPoints(0.1)
    .RightMargin = Application.InchesToPoints(0.1)
    .TopMargin = Application.InchesToPoints(0.3)
    .BottomMargin = Application.InchesToPoints(0.3)
    .Orientation = xlLandscape
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 10
End With
End Sub

My only problem is that I would like the number of pages tall to be a function of the number of lines (ie 100 lines per pages). Is this doable or do I need to forget about it? I tried by using LR and having a new parameter being LR / 100 but it returned a "application or object defined error".

Thanks in advance to anyone who can help.

IM
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hia
How about this
Code:
Sub Print_Format()
Dim LR As Long
Dim PageQty As Integer
LR = Range("A" & Rows.Count).End(xlUp).Row
pt = LR / 100
With ActiveSheet.PageSetup
    .PrintTitleRows = "1:1"
    .PrintArea = "A1:I" & LR
    .LeftMargin = Application.InchesToPoints(0.1)
    .RightMargin = Application.InchesToPoints(0.1)
    .TopMargin = Application.InchesToPoints(0.3)
    .BottomMargin = Application.InchesToPoints(0.3)
    .Orientation = xlLandscape
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = PageQty
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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