Rows To Repeat At Top

Programmatically set Rows to Repeat At Top using VBA

    Using VBA we can programmatically set the "Rows to Repeat at Top" option found on the Sheet tab in Excel's Page Setup dialog.

    There are two ways we can do it. First, we can simply set a stock set of rows to repeat.

ActiveSheet.PageSetup.PrintTitleRows = "$1:$1"

    This instruction sets the "Rows to Repeat at Top" to row 1 of the active worksheet. Next, we can base it on the user selection.

ActiveSheet.PageSetup.PrintTitleRows = Selection.Areas(1).Address

    This instruction will set the option to whatever rows are selected, provided that you have selected at least one entire row. For example, select rows 1 through 3 and this code will set rows 1 through 3 to repeat at the top of your printout.

Site last updated July 26, 2010 @ 8:14 pm