Pushing an image to the following page if it is over the page break

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a procedure that pastes in a signature from another sheet, just below the bottom of a quote. Is there a way to push it to the next page if the signature ends up being half on one page and half on the next?

VBA Code:
Function LastRow()

    With Sheets("CSS_quote_sheet")
        LastRow = .Range("A:H").Find(What:="*", _
            After:=.Range("A1"), _
            Lookat:=xlPart, _
            LookIn:=xlFormulas, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlPrevious, _
            MatchCase:=False).Row
    End With
End Function
Sub cmdSig()
    Sheets("Sheet2").Shapes("ImgT").Copy
    ActiveSheet.Paste Destination:=ActiveSheet.Cells(1, 1)
    Selection.Top = Cells(LastRow, 1).Top + "100"
End Sub
 
I run the sub called push and it almost does what I need it to do. I just need the signature also to appear below any notes written under the required elements under the table. I have tried to modify the code but it will not appear below any notes written in a similar fashion to appearing below the table.

VBA Code:
Function LastRow()
'Dim LastRow As Long
    With Sheets("CSS_quote_sheet")
        LastRow = .Range("A:H").Find(What:="*", _
            After:=.Range("A1"), _
            Lookat:=xlPart, _
            LookIn:=xlFormulas, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlPrevious, _
            MatchCase:=False).Row
    End With
End Function

Sub push()


Dim a As Double, aa As Double, aaa As Double
Application.ScreenUpdating = False
    With Sheets("Sheet2")
        .Shapes("ImgG").Duplicate.Name = "Signature"
        .Shapes("Signature").Cut
    End With
        Sheets("CSS_quote_sheet").Cells(43, 1).PasteSpecial
        Sheets("CSS_quote_sheet").Shapes(Selection.Name).Name = "Signature"
        a = Sheets("CSS_quote_sheet").Cells(Rows.Count, 1).End(xlUp).Offset(1).Top + 140
        aa = Sheets("CSS_quote_sheet").Shapes("Signature").Height
        aaa = Rows(Sheets("CSS_quote_sheet").HPageBreaks(1).Location.Row).Top + 1
    With Sheets("CSS_quote_sheet").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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I forgot to put in the code I am trying to run. Here it is:

VBA Code:
        Function LastRow()
'Dim LastRow As Long
With Sheets("CSS_quote_sheet")
LastRow = .Range("A:H").Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
End With
End Function

Sub push()


Dim a As Double, aa As Double, aaa As Double
Application.ScreenUpdating = False
With Sheets("Sheet2")
.Shapes("ImgG").Duplicate.Name = "Signature"
.Shapes("Signature").Cut
End With
Sheets("CSS_quote_sheet").Cells(43, 1).PasteSpecial
Sheets("CSS_quote_sheet").Shapes(Selection.Name).Name = "Signature"
a = Sheets("CSS_quote_sheet").Cells(LastRow, 1).End(xlUp).Offset(1).Top + 140
aa = Sheets("CSS_quote_sheet").Shapes("Signature").Height
aaa = Rows(Sheets("CSS_quote_sheet").HPageBreaks(1).Location.Row).Top + 1
With Sheets("CSS_quote_sheet").Shapes("Signature")
.Left = ActiveSheet.Range("A1").Left
.Top = IIf(a + aa > aaa, aaa, a)
.Placement = 1
End With
Application.ScreenUpdating = True
End Sub

This code will not place the signature below any notes that are written in columns A:H.
 
Upvote 0
Thanks for your code, I modified it a bit more and got it to work with running the sub push.

VBA Code:
Function LastRow()
'Dim LastRow As Long
    With Sheets("CSS_quote_sheet")
        LastRow = .Range("A:H").Find(What:="*", _
            After:=.Range("A1"), _
            Lookat:=xlPart, _
            LookIn:=xlFormulas, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlPrevious, _
            MatchCase:=False).Row
    End With
End Function

Sub push()


Dim a As Double, aa As Double, aaa As Double
Application.ScreenUpdating = False
    With Sheets("Sheet2")
        .Shapes("ImgG").Duplicate.Name = "Signature"
        .Shapes("Signature").Cut
    End With
        Sheets("CSS_quote_sheet").Cells(43, 1).PasteSpecial
        Sheets("CSS_quote_sheet").Shapes(Selection.Name).Name = "Signature"
        a = Sheets("CSS_quote_sheet").Cells(LastRow, 1).Top + 140
        aa = Sheets("CSS_quote_sheet").Shapes("Signature").Height
        aaa = Rows(Sheets("CSS_quote_sheet").HPageBreaks(1).Location.Row).Top + 1
    With Sheets("CSS_quote_sheet").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
Actually, if the notes go onto the next page, using this code, the signature will appear in the top left corner of the second page, regardless of where the notes are.
 
Upvote 0
Actually, if the notes go onto the next page, using this code, the signature will appear in the top left corner of the second page, regardless of where the notes are.
I forgot to mention, the distance it appears under the table is the same distance it needs to appear under the notes, but using this code, the signature appears the set distance under the table but ignores the notes. The signature is pasted over the notes where it should be under them.
 
Upvote 0
Is this a continuation from here?

If you work with a table, which I don't use because I don't have any need for it, it changes all your finding last rows etc.
 
Upvote 0
Since posted that thread about 2 years ago, I can't remember what it was regarding but I know this thread wouldn't be a continuation from it.
 
Upvote 0
I am sure I had it working at some point. I do not know what I have done as now the signature is being pasted over any text that appears as notes under the table. The signature appears in the right spot if there are no notes but when there are notes, I need it to appear under the notes.

When I execute cmdPush, the signature appears as shown if there are no notes.
VBA Code:
Function LastRow()
'Dim LastRow As Long
    With Sheets("CSS_quote_sheet")
        LastRow = .Range("A:H").Find(What:="*", _
            After:=.Range("A1"), _
            Lookat:=xlPart, _
            LookIn:=xlFormulas, _
            SearchOrder:=xlByRows, _
            SearchDirection:=xlPrevious, _
            MatchCase:=False).Row
    End With
End Function

Sub cmdPush()
Dim a As Double, aa As Double, aaa As Double
Application.ScreenUpdating = False
    With Sheets("Sheet2")
        .Shapes("ImgG").Duplicate.Name = "Signature"
        .Shapes("Signature").Cut
    End With
        Sheets("CSS_quote_sheet").Cells(43, 1).PasteSpecial
        Sheets("CSS_quote_sheet").Shapes(Selection.Name).Name = "Signature"
        a = Sheets("CSS_quote_sheet").Cells(LastRow, 1).End(xlUp).Offset(1).Top
        aa = Sheets("CSS_quote_sheet").Shapes("Signature").Height
        aaa = Rows(Sheets("CSS_quote_sheet").HPageBreaks(1).Location.Row).Top + 1
    With Sheets("CSS_quote_sheet").Shapes("Signature")
        .Left = ActiveSheet.Range("A1").Left
        .Top = IIf(a + aa > aaa, aaa, a + 140)
        .Placement = 1
    End With
Application.ScreenUpdating = True
End Sub

1603234781507.png






If there are notes, the signature is pasted in over the top of them like in this image
1603235434183.png





I need the signature to appear in the position it is in if there are no notes but if there are notes, I need it below any notes. At the moment, it will not appear under any notes that are written.

Another issue is that if there has been enough rows added to the table or enough notes written under the table to push the signature half way over the page, I want it pushed to the next page.
This is what it looks like at the moment if there is enough rows added but not enough to fully move it to the next page.
1603235778013.png



I have been getting some help with the coding but I am getting very confused and not sure what to do.

Please help someone,
Thanks :)
 
Upvote 0
You showed 3 pictures here. For each of these, what is the lastrow figure and what is the the "HPageBreaks(1).Location.Row).Top" number?
In the 1st picture, the "lastrow" row should be 24, in the 2nd it should be 30 and in the 3rd it should be 33.
It looks like, on picture #3 that the page break should be at the top of row 37.
If you have all the figures for the above, it should be simple arithmetic to see where it goes wrong.
It also looks like your signature picture is 4 rows high.
If your last row (= below data, notes etc) + signature height > 36, your print area needs to be 2 pages
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

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