Sub MakePageBreaks()
Dim c As Range
Dim FirstAddress As String
Dim FindWhat As String
FindWhat = "QJD TECHNICIAN PERFORMANCE REPORT"
With ActiveSheet.Cells
Set c = .Find(FindWhat, LookIn:=xlValues, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
If c.Row > 1 Then ActiveSheet.HPageBreaks.Add Before:=c
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
End If
End With
End Sub
Sub RemovePageBreaks()
Dim hb As HPageBreak
Dim cel As Range, celHome As Range
Dim i As Integer, n As Integer
Set celHome = ActiveCell
Cells(Rows.Count, Columns.Count).Select 'A bug in some Excel versions makes this step necessary
n = ActiveSheet.HPageBreaks.Count
If n > 0 Then
On Error Resume Next
For i = n To 1 Step -1
Set hb = ActiveSheet.HPageBreaks(i)
hb.Delete
Next
On Error GoTo 0
End If
Application.Goto celHome
End Sub
|