Help! How do I insert a manual page break on a change in cell contents

  • Thread starter Thread starter Al Dykes
  • Start date Start date
A

Al Dykes

If I sort spreedshet on Column A, I want to print a paper report that
starts a new page whenever the contents of col. A changes.

How?

TIA.
 
Hi,

Right click your sheet tab, view code and paste this in and run it

Sub marine()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set myrange = Range("A2:A" & lastrow)
For Each c In myrange
c.Select
If c.Value <> c.Offset(-1, 0).Value Then
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=ActiveCell
End If
Next
End Sub

Mike
 
Sub Insert_PBreak()
Dim OldVal As String
Dim rng As Range
OldVal = Range("A1")
For Each rng In Range("A1:A300") '<< change range
If rng.text <> OldVal Then
rng.PageBreak = xlPageBreakManual
OldVal = rng.text
End If
Next rng
End Sub


Gord Dibben MS Excel MVP
 

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

Back
Top