1 2 3 4 5 6 7 8 9 10 11 12 13 14
| sdp = Sheets(2).HPageBreaks.Count
If sdp > 0 Then
For i = 1 To sdp
pos = Sheets(2).HPageBreaks(i).Location.Row
If Sheets(2).Cells(pos, 7).Value <> "" And Sheets(2).Cells(pos - 2, 7).Value <> "" Then
j = Sheets(2).Cells(pos, 7).End(xlUp).Row
Sheets(2).Rows(j - 2 & ":" & j).Copy
Sheets(2).Rows(pos & ":" & pos + 2).Insert Shift:=xlDown
ElseIf Sheets(2).Cells(pos - 2, 7).Value = "" Then
Set Sheets(2).HPageBreaks(i).Location = Range("A" & pos - 2)
ElseIf Sheets(2).Cells(pos - 1, 7).Value = "" And Sheets(2).Cells(pos - 2, 7).Value = "" Then
Set Sheets(2).HPageBreaks(i).Location = Range("A" & pos - 1)
End If
Next i |