Add a page break every 40th row in a range

Status
Not open for further replies.

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I need a macro to add horizontal page break every 40th row within Sheet "Data" range AD3:AJ851

So first page break is AD43.

also I need it to set it so its One page wide.

Any ideas how I can do this?

Thanks

Tony
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi Thanks Jim but that was about doing it manually, I need a macro to do it automatically
 
Upvote 0
How about
Code:
Sub SetPageBreaks()
For i = 41 To Range("A" & Rows.Count).End(xlUp).row Step 40
    ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=Range("A" & i)
Next i
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
Fluff,

I tried to use that same code to manipulate my horizontal breaks, but it doesn't work. Any advice? The code I am running is below where a is the page I am on. So when a = 1, I want a break at row 44, when a = 2 at row 88 and so forth:

ThisWorkbook.Worksheets("Continuation Sheet " & Trim(Str(k + 1))).Activate
For a = 1 To sheetcount - 1
ThisWorkbook.Worksheets("Continuation Sheet " & Trim(Str(k + 1))).HPageBreaks.Add before:=Range("A" & (a * 44))
Next a

Any thoughts would be appreciated.

As a side note, I have also tried:


ThisWorkbook.Worksheets("Continuation Sheet " & Trim(Str(k + 1))).Range(sheetrange).rows(a * 44).EntireRow.PageBreak = xlPageBreakManual

Which did not work either.

Tom
 
Last edited:
Upvote 0
Have you tried the code I supplied in post#4?
 
Upvote 0
Fluff,

I tried to use that same code to manipulate my horizontal breaks, but it doesn't work. Any advice? The code I am running is below where a is the page I am on. So when a = 1, I want a break at row 44, when a = 2 at row 88 and so forth:

ThisWorkbook.Worksheets("Continuation Sheet " & Trim(Str(k + 1))).Activate
For a = 1 To sheetcount - 1
ThisWorkbook.Worksheets("Continuation Sheet " & Trim(Str(k + 1))).HPageBreaks.Add before:=Range("A" & (a * 44))
Next a

Any thoughts would be appreciated.

As a side note, I have also tried:


ThisWorkbook.Worksheets("Continuation Sheet " & Trim(Str(k + 1))).Range(sheetrange).rows(a * 44).EntireRow.PageBreak = xlPageBreakManual

Which did not work either.

Tom
Duplicate to https://www.mrexcel.com/forum/excel-questions/1064117-hpagebreaks-add.html

Please do not post the same question multiple times. Questions of a duplicate nature will be locked or deleted, per #12 of the Forum Rules and points 6 & 7 of the Forum Use Guidelines.

Any bumps, clarifications, or follow-ups should be posted to the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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