hassanleo1987
Board Regular
- Joined
- Apr 19, 2017
- Messages
- 56
Hi,
I am trying to reposition the last horizontal page break in a multipage table based on 2 criteria.
First criteria is to check the column A for a specific value (Lets say 999) and remember the row number of the cell where this criteria fits. (Lets say rcell).
Second criteria is to check whether the last HPageBreak is above or below the location (row) of 1st first criteria cell.
If the last page break is above the (rcell), then it should simply exit the loop / sub but if the last page break is below the (rcell) then it should insert a HPageBreak above (rcell) or offset the last HPageBreak to (rcell) location. (which ever is easier to do!).
So far I have not been successful in making one.
Here is my useless code.
Appreciate if somebody can help!
I am trying to reposition the last horizontal page break in a multipage table based on 2 criteria.
First criteria is to check the column A for a specific value (Lets say 999) and remember the row number of the cell where this criteria fits. (Lets say rcell).
Second criteria is to check whether the last HPageBreak is above or below the location (row) of 1st first criteria cell.
If the last page break is above the (rcell), then it should simply exit the loop / sub but if the last page break is below the (rcell) then it should insert a HPageBreak above (rcell) or offset the last HPageBreak to (rcell) location. (which ever is easier to do!).
So far I have not been successful in making one.
Here is my useless code.
VBA Code:
Sub InsertHPageBreaks1()
Dim rCell As Range
Dim hPB As HPageBreak
Dim lRow As Long
Set X = Worksheets(1).HPageBreaks
With hPB = X.Count - 1
For Each rCell In Range("A1", Cells(Rows.Count, "A").End(xlUp))
If rCell = 999 Then lRow = rCell.Row
If rCell.Row < hPB.Location.Row Then ActiveSheet.HPageBreaks.Add (rCell(2, 1))
Next rCell
End With
End Sub
Appreciate if somebody can help!