macro and automatic page break

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
 
L

Luke M

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
 
Y

yepidu

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!*
 
Y

yepidu

this didn't make any difference, I am still getting a page break before and
after the data in column F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

page break automatic macro 0
VBA Help 3
Cell Formatting 5
Remove Identical words 0
automatic page break 1
Macro for comparing columns and highlighting matching/differences 13
Cell Highlight 2
Cell Highlighting 3

Top