How to identify the last page break in a sheet

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
How can I find the position of the last page break in my sheet? There may be multiple pages and I want to know how to find the position of the first page break below the last row.
 
I don't have Excel at the moment, but try....Step through with F8 to see what happens and where it may error !
VBA Code:
Sub cmdPush(user As String)
Dim a As Double, aa As Double, aaa As Double, DividerBottom As Long
Dim NoPages As Long, ws As Worksheet, n As Long
Set ws = Sheets("CSS_quote_sheet")
'Finds the number of pages
n = ws.HPageBreaks.Count
NoPages = ((ActiveSheet.HPageBreaks.Count + 1) * (ActiveSheet.VPageBreaks.Count + 1)) / 2
Application.ScreenUpdating = False
    With Sheets("Sheet2")
        .Shapes(user).Duplicate.Name = "Signature"
        .Shapes("Signature").Cut
    End With
        ws.Cells(43, 1).PasteSpecial
        ws.Shapes(Selection.Name).Name = "Signature"
        a = ws.Cells(LastRow, 1).End(xlUp).Offset(1).Top + 140
        aa = ws.Shapes("Signature").Height
        aaa = ws.HPageBreaks(n).Location.Row - 1
        DividerBottom = ws.Shapes("Divider").BottomRightCell.Row
    With ws.Shapes("Signature")
        .Left = ActiveSheet.Range("A1").Left
        .Top = IIf(a + aa > aaa, aaa, a)
        .Placement = 1
    End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Is that code any different to mine, besides the variable names? Using my code, it doesn't error, just doesn't put the image in the right spot. Well, it does error on the NoSig sub but I have it commented out and will deal with it after I get this bit working.
 
Upvote 0
Rich (BB code):
Is that code any different to mine,
Not really....did you try it ??
 
Upvote 0
Ummm, why would I post it if it was the same ??
 
Upvote 0
Good point, I will try it when I am next at work on Friday.
 
Upvote 0
My sheet which has 4 pages of rows to the table, so the last row of the table is in row 108. Below the table there is a textbox called divider. Below that, there is place to write notes. If no notes are written, I want the image to be placed 140 below divider. If there are notes, I want the image to be 140 below the bottom note but if the image is spread across 2 pages, I want it pushed to the second page.

I tried your code from post 11 on my spreadsheet and the image was placed with the top of the image inline with the top of row 10. This is a snapshot of the sheet
CSS_quoting_tool_33.37.xlsm
ABCEFGH
9
10DateServiceUnit PriceHoursStaff Req.Kms TravelledPrice ex. GST
1116/07/2020Tutoring$73.1011$73.10
CSS_quote_sheet
Cell Formulas
RangeFormula
C11C11=IF([@Service]="Activities",[@Activities],INDEX(Service_Types,MATCH([@Service],Sheet2!$A$5:$A$12,0),MATCH([@[Day rate]],Sheet2!$A$5:$E$5,0)))
H11H11=IF([@Service]="Activities",ROUNDDOWN([@Activities]+[@[Transport $]],2),IF([@Service]="Carer Respite",[@[Staff Req.]]*[@Rate],ROUNDDOWN(((IF(OR(ISBLANK(A11),ISBLANK(D11),ISBLANK(B11)),0,[@[Transport $]]+[@MaxPay]))*[@[Staff Req.]]),2)))
 
Upvote 0
I'm up in Narrabri atm so will be offline for a few days. ..but I think you may have to look for another way around it
 
Upvote 0
AAGGGHHH, this is doing my head in. I have had to revert to having the image split across 2 pages if it is positioned at that point instead of being pushed to the second page. I couldn't get it working.
 
Upvote 0

Forum statistics

Threads
1,214,917
Messages
6,122,233
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top