Vba - insert page break

MRTERMINAL

New Member
Joined
Nov 28, 2005
Messages
35
Hi,

Can someone help me write a code to insert page break wherever there is an empty row:
eg

column A
ABC
123
456
EMPTY ROW
QWE
RTY
EMPTY ROW

Cheers,
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Code:
[color=darkblue]Sub[/color] Page_Breaks()
    [color=darkblue]Dim[/color] cell [color=darkblue]As[/color] Range
    [color=darkblue]For[/color] [color=darkblue]Each[/color] cell [color=darkblue]In[/color] Range("A:A").SpecialCells(xlCellTypeBlanks)
        ActiveSheet.HPageBreaks.Add Before:=cell
    [color=darkblue]Next[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Many thanks. That worked.
I also have another workbook where I need to insert page break just below text "Total Cost" (wherever it appears) in column D
 
Upvote 0
Code:
[color=darkblue]Sub[/color] Total_Cost_Page_Breaks()
    [color=darkblue]Dim[/color] cell [color=darkblue]As[/color] Range
    [color=darkblue]If[/color] ActiveSheet.FilterMode [color=darkblue]Then[/color] ActiveSheet.ShowAllData
    Cells.PageBreak = xlNone    [color=green]'Delete previous page breaks[/color]
    Range("A1", Range("A" & Rows.Count).End(xlUp)).AutoFilter 1, "Total Cost"
    [color=darkblue]For[/color] [color=darkblue]Each[/color] cell [color=darkblue]In[/color] Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
        ActiveSheet.HPageBreaks.Add Before:=cell.Offset(1)
    [color=darkblue]Next[/color]
    ActiveSheet.AutoFilterMode = [color=darkblue]False[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Ah, sometimes the forum page takes a bit longer to refresh, and it seems the post has disappeared.......then once you repost BOTH of the darn things appear.
Tip for future posts.....If it does happen, just reply to the first post with "Duplicate" and if you need to insert the address of the nerw post as well.....so you don't miss out altogether....(y)
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,510
Members
448,967
Latest member
screechyboy79

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