ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Insert page break (https://www.excelbanter.com/excel-programming/445052-insert-page-break.html)

Norvascom

Insert page break
 
Hi,

I have a long report with several lines on worksheet "Sheet1".
I would like to have a code that would insert a page break every time
there is the word "Break" on column C.
Note that the page break would be just above the line indicating
"Break".

Thanks in advance for your help.

Don Guillett[_2_]

Insert page break
 

Sub dopagbreaks()
ActiveSheet.ResetAllPageBreaks

With Range("c1:c500")
Set c = .Find("Break", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
ActiveSheet.HPageBreaks.Add Befo=Rows(c.Row)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
End Sub



On Oct 14, 12:28*pm, Norvascom wrote:
Hi,

I have a long report with several lines on worksheet "Sheet1".
I would like to have a code that would insert a page break every time
there is the word "Break" on column C.
Note that the page break would be just above the line indicating
"Break".

Thanks in advance for your help.



isabelle

Insert page break
 
hi Norvascom,

Sub AddHPageBreaks()
For i = 1 To Range("C65536").End(xlUp).Row
If Range("C" & i) = "Break" Then ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=Range("C" & i)
Next
End Sub

Sub DeleteHPageBreaks()
For i = ActiveSheet.HPageBreaks.Count To 1 Step -1
ActiveSheet.HPageBreaks(i).Delete
Next
End Sub


--
isabelle




Le 2011-10-14 13:28, Norvascom a écrit :
Hi,

I have a long report with several lines on worksheet "Sheet1".
I would like to have a code that would insert a page break every time
there is the word "Break" on column C.
Note that the page break would be just above the line indicating
"Break".

Thanks in advance for your help.


isabelle

Insert page break
 
for a large data range, the macro will be more faster by using "Find... Next"


--
isabelle





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com