ThomasLafferty
Instructor
I am using a macro to repetitively paste a preformatted block of cells. This block will vary in size according to user input. Unfortunately, this means that occasionally a block of formatted cells will fall across a horizontal page break. If this occurs, I would like to paste the whole block at the top of the next available page.
Visually, here's what I mean:
Here is the relevant part of the code I am using:
I have manually inserted page breaks before row 59, 117, 175 etc (every 58 rows thereafter ending at row 696).
I know how to test the location of a given page break, but I'm not sure how to incorporate this:
What I will need to check is if data appears in row 58 and 59 or 116 and 117 etc.
Any thoughts?
Tom
Born once die twice; born twice die once.
Visually, here's what I mean:
Code:
BEFORE
____________
| |
| CELLS |
[!]_|__________|__
| |[/!]
| |
|__________|
Code:
AFTER
[!]____________[/!]
| |
| CELLS |
| |
| |
| |
|__________|
Here is the relevant part of the code I am using:
Code:
'Find and copy range
Sheets("Layout").Select
Set Target = Cells(intRowStart, 1)
Range(Target, Cells(Target.Row + intRowCount, intColumnCount)).Copy
'Determine number of copies to make (times to paste)
If Commodities = Destinations Then
intTablesToPaste = Commodities
Else
If Commodities < Destinations Then
intTablesToPaste = Commodities
Else
intTablesToPaste = Destinations
End If
End If
'Build tables on rate letter
Sheets("Rates").Select
'Reinitialize variable
Set Target = Cells(19, 1)
For BuildTable = 1 To intTablesToPaste
If BuildTable = 1 Then
Target.Select
ActiveSheet.Paste
Else
[!]'Need to test for HPageBreak here[/!]
Target.Offset(intRowCount + 2, 0).Select
Set Target = Selection
ActiveSheet.Paste
End If
Next BuildTable
I have manually inserted page breaks before row 59, 117, 175 etc (every 58 rows thereafter ending at row 696).
I know how to test the location of a given page break, but I'm not sure how to incorporate this:
Code:
HPB = Sheets(2).HPageBreak(1).Location.Row
What I will need to check is if data appears in row 58 and 59 or 116 and 117 etc.
Any thoughts?
Tom
Born once die twice; born twice die once.