Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ben Ben is offline
external usenet poster
 
Posts: 509
Default print a new page for each group

is it possible to have a page break automatically inserted when there is a
change in value in a particular column?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default print a new page for each group

You can try out the below macro. If you are new to macros..

--Set the Security level to low/medium in (Tools|Macro|Security).
--From workbook launch VBE using short-key Alt+F11.
--From menu 'Insert' a module and paste the below code.
--Get back to Workbook.
--Run macro from Tools|Macro|Run <selected macro()
--Assume you have the data in ColA starting from row2. and Row1
with headers...The macro will insert pagebreaks after each group of data in
Col A. Try print preview once you run the macro and feedback

Invoice Num | Part no. | Qty.
H0907-001 ERW123 20,000
H0907-001 EAW122 10,000
-----------------------------------
H0907-002 AWE112 50,000
H0907-003 BPR225 10,000
-----------------------------------
H0907-003 CRE123 5,000
-----------------------------------

Sub Pagebreaks()
Dim lngRow As Long
For lngRow = 3 To Cells(Rows.Count, "A").End(xlUp).Row + 1
If Range("A" & lngRow) < Range("A" & lngRow - 1) Then
ActiveSheet.HPageBreaks.Add Befo=Range("A" & lngRow)
End If
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Ben" wrote:

is it possible to have a page break automatically inserted when there is a
change in value in a particular column?

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default print a new page for each group

Forgot to mention that if the macro is run on a sample data as below. each
invoice group will be separated by a page-break

Invoice Num | Part no. | Qty.
H0907-001 ERW123 20,000
H0907-001 EAW122 10,000
H0907-002 AWE112 50,000
H0907-003 BPR225 10,000
H0907-003 CRE123 5,000

--
If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

You can try out the below macro. If you are new to macros..

--Set the Security level to low/medium in (Tools|Macro|Security).
--From workbook launch VBE using short-key Alt+F11.
--From menu 'Insert' a module and paste the below code.
--Get back to Workbook.
--Run macro from Tools|Macro|Run <selected macro()
--Assume you have the data in ColA starting from row2. and Row1
with headers...The macro will insert pagebreaks after each group of data in
Col A. Try print preview once you run the macro and feedback

Invoice Num | Part no. | Qty.
H0907-001 ERW123 20,000
H0907-001 EAW122 10,000
-----------------------------------
H0907-002 AWE112 50,000
H0907-003 BPR225 10,000
-----------------------------------
H0907-003 CRE123 5,000
-----------------------------------

Sub Pagebreaks()
Dim lngRow As Long
For lngRow = 3 To Cells(Rows.Count, "A").End(xlUp).Row + 1
If Range("A" & lngRow) < Range("A" & lngRow - 1) Then
ActiveSheet.HPageBreaks.Add Befo=Range("A" & lngRow)
End If
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Ben" wrote:

is it possible to have a page break automatically inserted when there is a
change in value in a particular column?

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default print a new page for each group

Give this macro a try...

Sub InsertPageBreaks()
Dim X As Long, LastRow As Long
Const ColumnToMonitor As String = "E"
Const StartRow As Long = 2 'Assumes Row 1 is a header row
With ActiveSheet
LastRow = .Cells(.Rows.Count, ColumnToMonitor).End(xlUp).Row
For X = StartRow + 1 To LastRow
If .Cells(X, ColumnToMonitor).Value < _
.Cells(X - 1, ColumnToMonitor).Value Then
.Rows(X).PageBreak = xlPageBreakManual
End If
Next
End With
End Sub

Set the ColumnToMonitor (which column has the values you are checking) and
the StartRow for your actual setup.

--
Rick (MVP - Excel)


"Ben" wrote in message
...
is it possible to have a page break automatically inserted when there is a
change in value in a particular column?


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default print a new page for each group

Actually, use this macro instead... it allows you to change the break point
between existing sections and moves the breakpoints accordingly (actually,
it doesn't move them, it deletes all existing ones and then calculates the
position for the column as it currently exists).

Sub InsertPageBreaks()
Dim X As Long, LastRow As Long
Const ColumnToMonitor As String = "E"
Const StartRow As Long = 2 'Assumes Row 1 is a header row
With ActiveSheet
LastRow = .Cells(.Rows.Count, ColumnToMonitor).End(xlUp).Row
.Rows.PageBreak = xlNone
For X = StartRow + 1 To LastRow
If .Cells(X, ColumnToMonitor).Value < _
.Cells(X - 1, ColumnToMonitor).Value Then
.Rows(X).PageBreak = xlPageBreakManual
End If
Next
End With
End Sub

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Give this macro a try...

Sub InsertPageBreaks()
Dim X As Long, LastRow As Long
Const ColumnToMonitor As String = "E"
Const StartRow As Long = 2 'Assumes Row 1 is a header row
With ActiveSheet
LastRow = .Cells(.Rows.Count, ColumnToMonitor).End(xlUp).Row
For X = StartRow + 1 To LastRow
If .Cells(X, ColumnToMonitor).Value < _
.Cells(X - 1, ColumnToMonitor).Value Then
.Rows(X).PageBreak = xlPageBreakManual
End If
Next
End With
End Sub

Set the ColumnToMonitor (which column has the values you are checking) and
the StartRow for your actual setup.

--
Rick (MVP - Excel)


"Ben" wrote in message
...
is it possible to have a page break automatically inserted when there is
a
change in value in a particular column?





  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,766
Default print a new page for each group

Hi,

Fist sort in alphabetical order the column containing the value based on
which you want to create a break. Then go to Data Subtotal and check the
box for Page break between groups.

--
Regards,

Ashish Mathur
Microsoft Excel MVP
www.ashishmathur.com

"Ben" wrote in message
...
is it possible to have a page break automatically inserted when there is a
change in value in a particular column?


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 you print single page multiply times with increasing page . aliasmith Excel Worksheet Functions 2 September 26th 08 12:30 AM
Setting the print area in page set up to print 1 page wide by 2 pages tall EA[_2_] Excel Discussion (Misc queries) 2 July 12th 07 08:39 PM
PRINT PAGE BREAK VIEW AS WATERMARK FIOR EACH PAGE RALPH Setting up and Configuration of Excel 3 March 16th 06 11:08 PM
Active cell counting in particular print page (one sheet having different print area) ananthmca2004 Excel Worksheet Functions 1 November 24th 05 11:29 AM
How do I print a one page spreadsheet multiple time, each with its own page number? lhsallwasser Excel Discussion (Misc queries) 4 August 17th 05 03:00 PM


All times are GMT +1. The time now is 01:34 PM.

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

About Us

"It's about Microsoft Excel"