Insert page break at each blank row then...

HotLanta

Board Regular
Joined
Nov 3, 2005
Messages
176
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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
Brian,

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

Thank you for your help!
 
Upvote 0
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!
 
Upvote 0
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]
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,603
Members
449,038
Latest member
Arbind kumar

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