Rows disappear

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
My spreadsheet has 41 rows, I run the following code and it takes 4 rows of the bottom, just as if the margins get expanded but I don't want the rows to disappear. What is wrong with it?

This is the code that is run
VBA Code:
Sub AddRows()
Dim WS As Worksheet
Set WS = ThisWorkbook.Worksheets("ACA_Quoting")
    Call Move_Shape
        With WS
            .Range("A" & Rows.Count).End(xlUp).Offset(10, 0).PageBreak = xlPageBreakManual
            .Range("A8:V32").Copy .Range("A" & Rows.Count).End(xlUp).Offset(10, 0)         'Pastes a copy of the table below current table between the bottom of the table and the totals
        End With
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Haven't got an autofilter on, have you ??
 
Upvote 0
Hard to tell without seeing your sheet layout. Perhaps you have to copy\paste first, and insert a page break in between?

VBA Code:
Sub AddRows()
    Call Move_Shape
    With ThisWorkbook.Worksheets("ACA_Quoting").Range("A" & Rows.Count).End(xlUp).Offset(10, 0)
        .Parent.Range("A8:V32").Copy .Cells        'Pastes a copy of the table below current table between the bottom of the table and the totals
        .PageBreak = xlPageBreakManual
    End With
End Sub
 
Upvote 0
Here is some further information about the spreadsheet. I can't upload it but here are some screen shots. Notice how the gap seems to get bigger as more pages are made.

I want each new page to be an exact replica of the first page before the copy sub is run.


Let me know if you need aNYthing else.
 

Attachments

  • after second time copy is run.png
    after second time copy is run.png
    20.9 KB · Views: 3
  • after third time copy is run.png
    after third time copy is run.png
    22.7 KB · Views: 3
  • before copy is run.png
    before copy is run.png
    26.3 KB · Views: 4
Upvote 0
Ok, on looking at the pictures, it seems there is more getting copied than just the required ranges....
OR
the pageBreak is creating a pagefit break.
Without a copy to work on it's a bit hard to tel....
Can you create a copy of that worksheet with relevent code and Upload that ??
 
Upvote 0
Dave
Reduce the size of your header !
I think that may be causing the problem.......or remove it altogether, if it has nothing in it !!!
 
Upvote 0
Can't see column Letters in your pics, but it looks like column A is empty and you're using it in the code to determine the last used row. Column B ends (can't count the buttons) four rows above the totals in D and E. Perhaps use column D to determine the last row? Alternatively, offset 14 from the last row in column A or B instead of 10.

Rich (BB code):
Sub AddRows()
    Dim LastRow As Long
    Call Move_Shape
    With ThisWorkbook.Worksheets("ACA_Quoting")
        LastRow = .Range("D" & Rows.Count).End(xlUp).Row + 10
        .Range("A8:V32").Copy .Range("A" & LastRow)      'Pastes a copy of the table below current table between the bottom of the table and the totals
        .Rows(LastRow).PageBreak = xlPageBreakManual
    End With
End Sub
 
Upvote 0
This seems to work OK for me..
AND
I think the code provided by @AlphaFrog also does the trick
VBA Code:
Sub AddRows()
Dim WS As Worksheet, lr As Long
Set WS = ThisWorkbook.Worksheets("ACA_Quoting")
    Call Move_Shape
        With WS
            lr = .Range("A" & Rows.Count).End(xlUp).Row
            .Range("A8:V32").Copy .Range("A" & Rows.Count).End(xlUp).Offset(16, 0)         'Pastes a copy of the table below current table between the bottom of the table and the totals
            .Range("A" & Rows.Count).End(xlUp).Offset(16, 0).PageBreak = xlPageBreakManual
        End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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