The code has been reworked to allow the initial position of the footer to be placed anywhere after the header..adam wrote: Does this mean the code cannot be adjusted to work if I place the footer on the last page after the last data row?
Code: Select all
Option Explicit
Sub repeatBotRows()
Dim HdrRows As Long
Dim BotRows As Range, BotCount As Long
Dim FirstPgBk As Long, LasRow As Long
Dim TotPages As Long, n As Long, m As Long
Dim TSN As String ' Active Sheet Name
Dim FFR As Long
Dim RRPP As Long ' Repeating rows per page
10 Application.ScreenUpdating = False
20 Application.DisplayAlerts = False
30 Application.Calculation = xlCalculationManual
40 On Error Resume Next
50 Sheets("PrintOrig").Delete
60 On Error GoTo 0
'#####################################
'Identify the Target Sheet Name #
70 TSN = "StockInformation"
'#####################################
' Identify the Header & Footer rows '#
80 HdrRows = 12
90 Set BotRows = Range("160:164")
'#####################################
100 Worksheets(TSN).Copy After:=Worksheets(TSN)
110 ActiveSheet.Name = "PrintOrig"
120 With ActiveSheet.PageSetup
130 .PrintTitleRows = "$1:$" & HdrRows
140 .PrintArea = ""
150 End With
160 BotCount = BotRows.Rows.Count
170 Range(Rows(HdrRows + 1), Rows(HdrRows + BotCount)).Select
180 Selection.EntireRow.Insert Shift:=xlDown
190 Set BotRows = Range(Rows(BotRows.Row + BotCount), Rows(BotRows.Row + 2 * BotCount - 1))
200 BotRows.Copy Range("a" & HdrRows + 1)
210 Range(Rows(BotRows.Row), Rows(BotRows.Row + BotCount - 1)).Delete
220 Set BotRows = Range(Rows(HdrRows + 1), Rows(HdrRows + BotCount))
230 FirstPgBk = ActiveSheet.HPageBreaks(1).Location.Row - 1
240 RRPP = FirstPgBk - HdrRows - BotCount
250 LasRow = Cells.Find("*", [a1], , , xlByRows, xlPrevious).Row
260 TotPages = Application.Ceiling((LasRow - HdrRows - BotCount) / (FirstPgBk - BotCount - HdrRows), 1)
270 Range(Rows(FirstPgBk + 1), Rows(FirstPgBk + BotCount)).Select
280 Selection.EntireRow.Insert Shift:=xlDown
290 Set BotRows = Range(BotRows.Row & ":" & BotRows.Row + BotRows.Rows.Count - 1)
300 BotRows.Copy Range("A" & FirstPgBk + 1)
310 FFR = FirstPgBk - BotCount + 1
320 Range(BotRows.Row & ":" & BotRows.Row + BotCount - 1).Delete
330 n = 2 ' curent page
340 Do
350 Range(Rows((FirstPgBk - HdrRows) * n + HdrRows), Rows((FirstPgBk - HdrRows) * n + HdrRows - BotCount + 1)).Select
360 Selection.EntireRow.Insert Shift:=xlDown
370 Range(FFR & ":" & FirstPgBk).Copy Range("A" & Selection.Row)
380 n = n + 1
390 Loop Until n > TotPages
400 Application.Calculation = xlCalculationAutomatic
'410 ActiveSheet.PrintOut
420 ActiveSheet.PrintPreview
430 Application.DisplayAlerts = True
End Sub