auto format page breaks

rwynn

New Member
Joined
Nov 13, 2005
Messages
1
Has anyone auto formatted page breaks based on column data. I have part numbers associated to bin numbers and want to make a new page for each change in the bin number.

thank you

rw
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Sub SetPageBreaksOnColA()
'Break on every value change.
Dim rng As Range, pageRows#, totalRows#, n#
Dim strLastValue As String
Dim strCurrValue As String

'Set rng = Range([A1], Cells.SpecialCells(xlCellTypeLastCell))
totalRows = Worksheets("Sheet1").Range("A65536").End(xlUp).Row
n = 1
' turn off automatic page breaking
Worksheets("Sheet1").Rows(totalRows).PageBreak = xlPageBreakNone
strLastValue = Cells(1, 1).Value 'store first row value

Do Until n > totalRows
strCurrValue = Cells(n, 1).Value 'store first row value

If strCurrValue <> strLastValue Then
ActiveSheet.HPageBreaks.Add Before:=Rows(n)
strLastValue = strCurrValue
End If
n = n + 1
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,202,991
Messages
6,052,965
Members
444,622
Latest member
Kriszilla

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