Insert page break at each blank row then...

HotLanta

Board Regular
Joined
Nov 3, 2005
Messages
156
Hello -

Could someone help me code this:

I want to:

(1) Insert a page break at each blank row in my data set.
Then
(2) I want to copy row 1 down to each blank row in the data set.

Thanks for your help!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

brian.wethington

Well-known Member
Joined
Jul 20, 2006
Messages
1,739
Why not simply use the page setup, sheet tab, rows to repeat at top rather than copying again.

Now for the page break insertion.

Code:
LstRw = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For Each Ce In Range("A2:A" & LstRw)
    If Len(Ce.Value) = 0 Then
        ActiveSheet.HPageBreaks.Add Before:=Ce
    End If
Next
 

HotLanta

Board Regular
Joined
Nov 3, 2005
Messages
156
Brian,

I wasn't aware of the "page setup, sheet tab, rows to repeat at top" ability. I tried it and it was cool, but when I went to print preview - there was probably 5,000 blank pages (exaggeration) waiting to be printed.

Can this feature be set to only repeat the row in which there was data present on the sheet?

Oh and by the way the code for inserting pages breaks worked perfectly - thank you.
 

brian.wethington

Well-known Member
Joined
Jul 20, 2006
Messages
1,739
Brian,

I wasn't aware of the "page setup, sheet tab, rows to repeat at top" ability. I tried it and it was cool, but when I went to print preview - there was probably 5,000 blank pages (exaggeration) waiting to be printed.

Can this feature be set to only repeat the row in which there was data present on the sheet?

Oh and by the way the code for inserting pages breaks worked perfectly - thank you.

You may want to check your Print Area. As a default Excel will only go out as many columns as you have set in the print area for it to be repeated.
 

HotLanta

Board Regular
Joined
Nov 3, 2005
Messages
156

ADVERTISEMENT

Brian,

I found it - I had some "stray data way off in left field". Now everything works perfectly.

Thank you for your help!
 

HotLanta

Board Regular
Joined
Nov 3, 2005
Messages
156

ADVERTISEMENT

Brian (if you are still out there)

I revisited this code this morning for a different project. I was wondering if it would be possible to modify the code to place the page break AFTER each blank row.

LstRw = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For Each Ce In Range("A2:A" & LstRw)
If Len(Ce.Value) = 0 Then
ActiveSheet.HPageBreaks.Add Before:=Ce
End If
Next
End Sub

Thanks!
 

brian.wethington

Well-known Member
Joined
Jul 20, 2006
Messages
1,739
Sorry been out a while.. there are probably a few ways to handle this. One may look something like this, unfortunately I don't have time to test anything:

Code:
LstRw = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row 
For Each Ce In Range("A2:A" & LstRw) 
    If Len(Ce.Value) = 0 Then 
        ActiveSheet.HPageBreaks.Add Before:=Ce.Offset(1, 0)
    End If 
Next[code]
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,164
Messages
5,768,564
Members
425,482
Latest member
blazingdiva1

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