Conditional page break

  • Thread starter Thread starter N! Xau
  • Start date Start date
N

N! Xau

Hello everybody,
is there a way in Excel to insert page break(s) depending from datas?
Better: I have an invoice list:
invoice # amount article ecc..
1001 4000 C01 .....
1001 5000 C02
1001 4500 C03
1001 3000 C04
1005 6700 C01
1005 4000 C04
....

and I want a page break _after_ the invoice number changes.
Is it possible to do that?
Thanks
N! Xau
 
N! Xau, try this if your invoice numbers are in column A

Sub InsertBreaks()

Set rng = Range(Cells(2, 1), _
Cells(Rows.Count, 1).End(xlUp))

For Each cell In rng
If Trim(cell.Value) <> _
Trim(cell.Offset(-1, 0).Value) Then
ActiveSheet.HPageBreaks.Add cell
End If
Next
End Sub

--
Paul B
Always backup your data before trying something new
Using Excel 97 & 2000
Please post any response to the newsgroups so others can benefit from it
** remove news from my email address to reply by email **
 
Paul B said:
N! Xau, try this if your invoice numbers are in column A

Sub InsertBreaks()

Set rng = Range(Cells(2, 1), _
Cells(Rows.Count, 1).End(xlUp))

For Each cell In rng
If Trim(cell.Value) <> _
Trim(cell.Offset(-1, 0).Value) Then
ActiveSheet.HPageBreaks.Add cell
End If
Next
End Sub


thanks, but...

where should I add this code?
Do I have to create a macro and execute it "on the file"?

N! Xau
 
Back
Top