Hello,
I'm really struggling with this one. I have multiple ranges of rows on a worksheet. I'd like to find a way to insert a pagebreak before the first row of a range if these rows are on different pages.
I tried to use this macro to number each cell in column A according to page number. However I only get the page number of the active cell in my range. Is there a way to fix this?
I thought that after I was able to differentiate page numbers of my range of rows I'd be able to insert conditionnal pagebreak. Maybe there is an easier way?
Thank you for your time
I'm really struggling with this one. I have multiple ranges of rows on a worksheet. I'd like to find a way to insert a pagebreak before the first row of a range if these rows are on different pages.
I tried to use this macro to number each cell in column A according to page number. However I only get the page number of the active cell in my range. Is there a way to fix this?
I thought that after I was able to differentiate page numbers of my range of rows I'd be able to insert conditionnal pagebreak. Maybe there is an easier way?
Thank you for your time
VBA Code:
Sub pagenumber()
'updateby Extendoffice 20160506
Dim xVPC As Integer
Dim xHPC As Integer
Dim xVPB As VPageBreak
Dim xHPB As HPageBreak
Dim xNumPage As Integer
xHPC = 1
xVPC = 1
If ActiveSheet.PageSetup.Order = xlDownThenOver Then
xHPC = ActiveSheet.HPageBreaks.Count + 1
Else
xVPC = ActiveSheet.VPageBreaks.Count + 1
End If
xNumPage = 1
For Each xVPB In ActiveSheet.VPageBreaks
If xVPB.Location.Column > ActiveCell.Column Then Exit For
xNumPage = xNumPage + xHPC
Next
For Each xHPB In ActiveSheet.HPageBreaks
If xHPB.Location.Row > ActiveCell.Row Then Exit For
xNumPage = xNumPage + xVPC
Next
Range("A1:A250") = xNumPage
End Sub