Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Page Breaks based on cell data

Hi,

I was wondering if anyone knew how to create a macro to insert a page break
after a number of values in a column. For example:

Column A
Category
Cat
Cat
Cat
Dog
Dog
Sheep
Sheep
Sheep

I want to insert a page break in between cat and dog and in between dog and
sheep. Any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Page Breaks based on cell data

I'd use data|subtotals.

There's an option to insert page breaks between groups on that dialog.

And I could even get subtotals (counts, sums, averages,...) if I wanted them.

Josh Craig wrote:

Hi,

I was wondering if anyone knew how to create a macro to insert a page break
after a number of values in a column. For example:

Column A
Category
Cat
Cat
Cat
Dog
Dog
Sheep
Sheep
Sheep

I want to insert a page break in between cat and dog and in between dog and
sheep. Any ideas?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Page Breaks based on cell data

Hi Dave,

I've tried that and the page breaks are fine except I don't want any
subtotals or totals calculated. Unless you know of a way to get the page
breaks without excel making any calculations??

"Dave Peterson" wrote:

I'd use data|subtotals.

There's an option to insert page breaks between groups on that dialog.

And I could even get subtotals (counts, sums, averages,...) if I wanted them.

Josh Craig wrote:

Hi,

I was wondering if anyone knew how to create a macro to insert a page break
after a number of values in a column. For example:

Column A
Category
Cat
Cat
Cat
Dog
Dog
Sheep
Sheep
Sheep

I want to insert a page break in between cat and dog and in between dog and
sheep. Any ideas?


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Page Breaks based on cell data


Here is what i would do
Assuming the data in column a has been sorted i would write a macro
with the following code:

Sub pagebreak()
Dim value1 As String
Dim value2 As String

Range("A2").Select
Do While ActiveCell.Value < ""
value1 = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
value2 = ActiveCell.Value
If value1 < value2 Then
ActiveCell.EntireRow.Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=ActiveCell
Else
End If
Loop
End Sub


--
Steel Monkey
------------------------------------------------------------------------
Steel Monkey's Profile: http://www.excelforum.com/member.php...o&userid=29051
View this thread: http://www.excelforum.com/showthread...hreadid=558694

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Page Breaks based on cell data

Josh

Sub InsertBreak_At_Change()
Dim i As Long
For i = Selection.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, 5 Jul 2006 18:20:01 -0700, Josh Craig
wrote:

Hi Dave,

I've tried that and the page breaks are fine except I don't want any
subtotals or totals calculated. Unless you know of a way to get the page
breaks without excel making any calculations??

"Dave Peterson" wrote:

I'd use data|subtotals.

There's an option to insert page breaks between groups on that dialog.

And I could even get subtotals (counts, sums, averages,...) if I wanted them.

Josh Craig wrote:

Hi,

I was wondering if anyone knew how to create a macro to insert a page break
after a number of values in a column. For example:

Column A
Category
Cat
Cat
Cat
Dog
Dog
Sheep
Sheep
Sheep

I want to insert a page break in between cat and dog and in between dog and
sheep. Any ideas?


--

Dave Peterson




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Page Breaks based on cell data

Works like a charm. Thanks heaps, Steel Monkey.

"Steel Monkey" wrote:


Here is what i would do
Assuming the data in column a has been sorted i would write a macro
with the following code:

Sub pagebreak()
Dim value1 As String
Dim value2 As String

Range("A2").Select
Do While ActiveCell.Value < ""
value1 = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
value2 = ActiveCell.Value
If value1 < value2 Then
ActiveCell.EntireRow.Select
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=ActiveCell
Else
End If
Loop
End Sub


--
Steel Monkey
------------------------------------------------------------------------
Steel Monkey's Profile: http://www.excelforum.com/member.php...o&userid=29051
View this thread: http://www.excelforum.com/showthread...hreadid=558694


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 469
Default Page Breaks based on cell data

Looking at this I think it is in the direction of my problem. What I am
tryiong to do is set page break based on the size of cell in column (M). This
cell varies in size and I am trying to have its contents not split to second
page. I have never done page breaks before. If my idea is correct the
selection row could be changed to cell size? Cell is changed to wrap when
printing. All assistance greatly appreciated.
Thanks You

"Gord Dibben" wrote:

Josh

Sub InsertBreak_At_Change()
Dim i As Long
For i = Selection.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, 5 Jul 2006 18:20:01 -0700, Josh Craig
wrote:

Hi Dave,

I've tried that and the page breaks are fine except I don't want any
subtotals or totals calculated. Unless you know of a way to get the page
breaks without excel making any calculations??

"Dave Peterson" wrote:

I'd use data|subtotals.

There's an option to insert page breaks between groups on that dialog.

And I could even get subtotals (counts, sums, averages,...) if I wanted them.

Josh Craig wrote:

Hi,

I was wondering if anyone knew how to create a macro to insert a page break
after a number of values in a column. For example:

Column A
Category
Cat
Cat
Cat
Dog
Dog
Sheep
Sheep
Sheep

I want to insert a page break in between cat and dog and in between dog and
sheep. Any ideas?

--

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
When automatic page breaks are moved each cell becomes a new page Queso hotmail com> Excel Discussion (Misc queries) 0 March 30th 10 03:08 AM
Page breaks around every cell (Excel) Etobian Excel Discussion (Misc queries) 0 September 10th 08 11:52 PM
Page Breaks. They are showing up around every cell! Tammy Excel Discussion (Misc queries) 0 August 29th 08 09:00 PM
Auto insert page breaks in Excel, based on a sort of numbers peterc89 Excel Discussion (Misc queries) 0 November 9th 05 03:41 PM
Module to set Page Breaks based on criteria through code DoctorV[_4_] Excel Programming 0 July 20th 04 06:32 PM


All times are GMT +1. The time now is 01:22 AM.

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"