print areas in vba

markh1182

New Member
Joined
Apr 25, 2006
Messages
48
Hi,

I have this code that sets the print area. Is there a way to amend slightly so it says that each page should have 59 rows from the excel spreadsheet? This is because it is putting page breaks in weird places, and not just sticking to the page setup format, from the looks of it.

Ta,
Mark

Code:
Sub PrintArea()

bottom = ActiveSheet.Range("N65536").End(xlUp).Row

    Cells.Select
    ActiveSheet.PageSetup.PrintArea = ""
    
    Range("A1").Select
    
MyRange = ("I1" & ":" & "O" & bottom)

ActiveSheet.PageSetup.PrintArea = MyRange


End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi, Mark,

struggling for years with this from time to time, always feeling to need workarounds
why you cannot simply remove all those stupid automatic pagebreaks and put some yourself, is a mistery for me :confused:

this seems to work
Code:
Sub test()
Dim pb As HPageBreak
Dim i As Long

    For i = 1 To ActiveSheet.HPageBreaks.Count
    ActiveSheet.HPageBreaks(i).Location = Cells(i * 59, 1)
    Next i

End Sub
kind regards,
Erik
 

Forum statistics

Threads
1,137,292
Messages
5,680,648
Members
419,923
Latest member
Kalthus

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
Top