Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default insert page break at each change in column B

It sounds simple enough, but I haven't been able to find any information.

I need to insert a page break at each change of value in column B. For
example:

Column A = Name
Column B = Department

I need to insert a page break every time the department changes.

Any help would be greatly appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default insert page break at each change in column B

Maybe you could use data|subtotals (xl2003 menu system) to get subtotals -- make
sure you select page break between groups.



cbuck wrote:

It sounds simple enough, but I haven't been able to find any information.

I need to insert a page break at each change of value in column B. For
example:

Column A = Name
Column B = Department

I need to insert a page break every time the department changes.

Any help would be greatly appreciated!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default insert page break at each change in column B

Based on your column example and assuming you don't have a header row,
this code worked for me:

Option Explicit

Sub InsertPageBreaks()
Dim dX As Double, dRows As Double
Dim s1 As String, s2 As String

'get count of used rows
dRows = ActiveSheet.UsedRange.Rows.Count
'get initial value to start comparing with
s1 = Range("B1").Value

'loop through the rest of the values in column B
'starting in cell 2 (because you already know cell 1)
For dX = 2 To dRows
'get the next value
s2 = Cells(dX, 2).Value
'compare it
If s1 < s2 Then
'if the values are different then add the break
ActiveSheet.HPageBreaks.Add Befo=Cells(dX, 1)
'reset the value to compare
s1 = s2
End If
Next
End Sub


Hope that helps!
Cory

On Oct 31, 11:57 am, cbuck wrote:
It sounds simple enough, but I haven't been able to find any information.

I need to insert a page break at each change of value in column B. For
example:

Column A = Name
Column B = Department

I need to insert a page break every time the department changes.

Any help would be greatly appreciated!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default insert page break at each change in column B

Sub InsertBreak_At_Change()
Dim i As Long
For i = Columns(2).Rows.Count To 1 Step -1
If Selection(i).Row = 1 Then Exit Sub
If Selection(i) < Selection(i - 1) And Not IsEmpty _
(Selection(i - 1)) Then
With Selection(i)
.PageBreak = xlPageBreakManual
End With
End If
Next
End Sub


Gord Dibben MS Excel MVP

On Wed, 31 Oct 2007 09:57:01 -0700, cbuck
wrote:

It sounds simple enough, but I haven't been able to find any information.

I need to insert a page break at each change of value in column B. For
example:

Column A = Name
Column B = Department

I need to insert a page break every time the department changes.

Any help would be greatly appreciated!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default insert page break at each change in column B

Thank you, Dave. That was very helpful!

"Dave Peterson" wrote:

Maybe you could use data|subtotals (xl2003 menu system) to get subtotals -- make
sure you select page break between groups.



cbuck wrote:

It sounds simple enough, but I haven't been able to find any information.

I need to insert a page break at each change of value in column B. For
example:

Column A = Name
Column B = Department

I need to insert a page break every time the department changes.

Any help would be greatly appreciated!


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I insert a page break between every row and column? Ashley Excel Discussion (Misc queries) 2 February 26th 09 03:21 AM
Help! How do I insert a manual page break on a change in cell contents Al Dykes Excel Discussion (Misc queries) 2 July 23rd 08 09:25 PM
change and/or remove page number watermark in page break preview juga Excel Discussion (Misc queries) 2 December 25th 06 10:15 AM
insert page break when there is a change in the row value [email protected] Excel Worksheet Functions 3 July 14th 06 07:20 PM
How do I insert a page break before each change in the cell conten ronda Excel Programming 7 December 8th 04 12:29 AM


All times are GMT +1. The time now is 02:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"