Excel: how to insert page breaks between all the rows at once?

T

Thomas [PBD]

Kim,

Here is a macro that will accomplish what you are asking for. What it does
is add a page break on every row for all used cells.

Go to VBA (Tools>Macro>Visual Basic Editor) and create a new Module for the
coding (Insert>Module) and paste this code in, close VBA.
Run the Macro from Excel (Tools>Macro>Macros>Add_PageBreaks)

Public Sub Add_PageBreaks()
Dim xlssheet As Worksheet
Set xlssheet = Excel.ActiveSheet
Dim x As Long
Dim y As Long
Dim actcell As String
y = xlssheet.UsedRange.Rows.Count


For x = 2 To y
actcell = "$A$" & x
xlssheet.Range(actcell).Select
ActiveWindow.SelectedSheets.HPageBreaks.Add before:=ActiveCell
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top