Rows to Repeat at Top

If you want to programmatically set the "Rows to Repeat At Top" option on the Sheet tab in Excel's Page Setup dialog box, here are two ways to do it.

If you already know what range you want, you could use this code:

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

This would set row 1 (which would ideally be a list of column headers) to print at the top of every page.

To set this option based on a user selection:

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

This code assumes that you have selected at least one entire row, i.e. select rows 1 through 4 then use the code above to set "Rows to repeat at top" to $1:$4.

HTH,
JP

Related Articles:

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »

Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

comment bubble 3 Comments:

  1. mary writes:

    Excellent tip!! I've always puzzled over how to do this.

    Thanks for another awesome post. I love Excel :)

  2. Cheryl writes:

    I have multiple page documents where I use the repeat function for selected rows.. I need this function on all pages to print on the top except the last one.
    Is there a way to define what pages for the selected rows to print on?

Comments on this article are closed. Why?

Site last updated: February 9, 2012