Sunday, August 6, 2023

Repeat Rows At Excel Bottom using VBA

 Sub repeatBotRows()


Dim botRows As Range, botCount As Long

Dim firstPgBk As Long, LasRow As Long

Dim totPages As Long, n As Long, m As Long


Application.ScreenUpdating = False

Application.DisplayAlerts = False

Application.Calculation = xlCalculationManual


Set botRows = Range("2:7")

Sheets("Sheet1").Copy after:=Sheets("Sheets1")

ActiveSheet.Name = "printOrig"

With ActiveSheet.PageSetup

.PrintTitleRows = "$1:$1"

End With

firstPgBk = ActiveSheet.HPageBreaks(1).Location.Row - 1

botCount = botRows.Rows.Count

LasRow = Cells.Find("*", [a1], , , xlByRows, xlPrevious).Row

totPages = Application.Ceiling(LasRow / (firstPgBk - botCount - 1), 1)

Range(Rows(firstPgBk - botCount + 1), Rows(firstPgBk)).Select

Selection.EntireRow.Insert Shift:=xlDown

botRows.Copy Range("A" & firstPgBk - botCount + 1)


n = 2

m = 0

Do

Range(Rows(firstPgBk * n - botCount - m), Rows(firstPgBk * n - m - 1)).Select

Selection.EntireRow.Insert Shift:=xlDown

botRows.Copy Range("A" & firstPgBk * n - botCount - m)

n = n + 1

m = m + 1

Loop Until n > totPages

Application.Calculation = xlCalculationAutomatic

' ActiveSheet.PrintOut

' ActiveSheet.Delete

ActiveSheet.Buttons.Delete

Application.DisplayAlerts = True

End Sub


No comments:

Post a Comment

Office 2021 Activation using command

  @echo off title Activate Microsoft Office 2021 (ALL versions) for FREE - office.com&cls&echo =====================================...