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

Cell Formatting 5
VBA Help 3
automatic page break 1
Cell Highlight 2
Cell Highlighting 3
Page break problem 3
Macro for comparing columns and highlighting matching/differences 14
Inserting header @ page break 1

Top