VBA to Insert Page Breaks every nth row, getting info from cell value

scottclayton

New Member
Joined
Apr 20, 2014
Messages
8
Greetings Excelers

I appear to be stuck on inserting page rows every nth line by getting that value from a cell value on each sheet.

With each sheet, cell BA2 is going to have a number in it, for example, 57, which is the number of rows to print on a page. Cell BA3 will have a value of the furthest-down row to print—e.g. 4218.

I'm trying to set it that for each worksheet selected, the sheet will be .FitToPagesWide = 1, and .FitToPagesTall = False, with page breaks after each BA2 rows. In case we need to know the number of rows down the last printable info is, BA3 has that value—end(xldown) won't work for this.

I'm automating a label-maker that has sheets with varying label sizes, and sometimes I might print a half-dozen sheets at once, but printers often have different margins, and different margins depending on the computer talking to it, which is annoying.

Anyone have any ideas?

Thanks!


-Scott
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Welcome to the forum. This is not very difficult. I have done it several times.

Replying now so that I can find the thread tomorrow when I am at work and have access to my code.

it will look something like :
Code:
Dim currRow As Long
Dim theSht As Worksheet


For Each theSht In ActiveWorkbook.Sheets
    currRow = theSht.Cells(2, 53)
    While currRow < theSht.Cells(3, 53)
        theSht.Rows(currRow).PageBreak = xlPageBreakManual
        currRow = currRow + theSht.Cells(2, 53)
    Wend
Next
 
Upvote 0
Good. Thanks for the feedback. There are a few things that you will probably want to add.

Disable screen updating and recalculation. It will speed things up.

You can also set the page width in there for each sheet using the PageSetup object.
 
Upvote 0

Forum statistics

Threads
1,216,303
Messages
6,129,983
Members
449,549
Latest member
birdguy_1930

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