ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   macro and automatic page break (https://www.excelbanter.com/excel-discussion-misc-queries/247354-macro-automatic-page-break.html)

yepidu

macro and automatic page break
 
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 Befo=Range("F" & IngRow)
End If
Next

End

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

--
yepidu

Luke M

macro and automatic page break
 
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 Befo=Range("F" & IngRow)
End If
Next

End


--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"yepidu" wrote:

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 Befo=Range("F" & IngRow)
End If
Next

End

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

--
yepidu


yepidu

macro and automatic page break
 
Thank you I will try that.
--
yepidu


"Luke M" wrote:

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 Befo=Range("F" & IngRow)
End If
Next

End


--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"yepidu" wrote:

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 Befo=Range("F" & IngRow)
End If
Next

End

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

--
yepidu


yepidu

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


"yepidu" wrote:

Thank you I will try that.
--
yepidu


"Luke M" wrote:

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 Befo=Range("F" & IngRow)
End If
Next

End


--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"yepidu" wrote:

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 Befo=Range("F" & IngRow)
End If
Next

End

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

--
yepidu



All times are GMT +1. The time now is 06:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com