Option Explicit
Sub changePageBreaks()
Dim counter As Integer
Dim hA
Dim sheetNumber As Integer
Dim I As Integer
Dim n As Long
Dim LineNumber As Long
Dim rng As Range
Dim aRow As Long
Dim bRow As Long
sheetNumber = ActiveWorkbook.Sheets.Count
For counter = 1 To sheetNumber
Sheets(counter).Activate
With ActiveSheet
If .HPageBreaks.Count > 0 Then
ReDim hA(0 To .HPageBreaks.Count)
Debug.Print ActiveSheet.HPageBreaks.Count
hA(0) = 1
For I = 1 To UBound(hA)
hA(I) = .HPageBreaks(I).Location.Row
Set rng = .HPageBreaks(I).Location
Debug.Print rng.Address
LineNumber = rng.Row
Debug.Print LineNumber
If Cells(.HPageBreaks(I).Location.Row).Interior.ColorIndex <> 15 Then
aRow = .HPageBreaks(I).Location.Row - 1
.HPageBreaks(I).Delete
ActiveSheet.HPageBreaks.Add Before:=Rows(aRow)
ElseIf Cells(.HPageBreaks(I).Location.Row, 1).Interior.ColorIndex <> 15 Then
bRow = .HPageBreaks(I).Location.Row - 2
.HPageBreaks(I).Delete
ActiveSheet.HPageBreaks.Add Before:=Rows(bRow)
End If
Next I
Else
ReDim hA(0 To 0)
hA(0) = 0
End If
End With
Next counter
End Sub