Back

About MrExcel
Consulting Services
Learn Excel Resources
Challenge of the Month
MrExcel Seminars

Message Board

MrExcel Store
Podcast
Search
Contact
Home

 

 

Past Tip of the Day

 

"S" (why can't people sign their e-mail with at least a first name?) wrote today's question. I am trying to automatically put page breaks into a table in Excel. I tried Data - Subtotals, but that forces me to add a Sum or a Count. I don't want any subtotals, just a page break whenever the value in column A changes.

This macro will solve the problem. For some reason, macros that change page breaks or page setups take a long time to run, but this will certainly be faster that doing the process manually. The macro assumes your data is in column A and that it starts in row 2.


Sub AddBreaks()
StartRow = 2
FinalRow = Range("A65536").End(xlUp).Row
LastVal = Cells(StartRow, 1).Value

For i = StartRow To FinalRow
ThisVal = Cells(i, 1).Value
If Not ThisVal = LastVal Then
ActiveSheet.HPageBreaks.Add _
before:=Cells(i, 1)
End If
LastVal = ThisVal
Next i
End Sub

By Bill Jelen on 10-Nov-2001

MrExcel.com Consulting can be hired to implement this concept, or many other cool applications, with your data.

MrExcel.com provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures on this web site are provided "as is" and we do not guarantee that they can be used in all situations.

 

Excel is a registered trademark of the Microsoft® Corporation.

All contents Copyright 1998-2008 by MrExcel Consulting.