macro and automatic page break

  • Thread starter Thread starter yepidu
  • Start date Start date
Y

yepidu

I need to insert a page break when 2 conditions are met.

I currently have:
Sub PageBreak()
Dim IngRow As Long
For IngRow = 2 To Cells(Rows.Count, "D").End(xlUp).Row + 1
If Range("D" & IngRow) <> Range("D" & IngRow - 1) Then
ActiveSheet.HPageBreaks.Add Before:=Range("F" & IngRow)
End If
Next

End

But I also need consider if column F is greater than 0, insert page break
after row
 
Adjust to suit:

Sub PageBreak()
Dim IngRow As Long
For IngRow = 2 To Cells(Rows.Count, "D").End(xlUp).Row + 1
'Added criteria
If Range("D" & IngRow) <> Range("D" & IngRow - 1) And _
Range("F"&IngRow) > 0 Then
ActiveSheet.HPageBreaks.Add Before:=Range("F" & IngRow)
End If
Next

End
 
Thank you I will try that.
--
yepidu


Luke M said:
Adjust to suit:

Sub PageBreak()
Dim IngRow As Long
For IngRow = 2 To Cells(Rows.Count, "D").End(xlUp).Row + 1
'Added criteria
If Range("D" & IngRow) <> Range("D" & IngRow - 1) And _
Range("F"&IngRow) > 0 Then
ActiveSheet.HPageBreaks.Add Before:=Range("F" & IngRow)
End If
Next

End


--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*
 
this didn't make any difference, I am still getting a page break before and
after the data in column F
 
Back
Top