Copying Headers or Footers within a Workbook

Written by Allen Wyatt (last updated July 15, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


5

Ross has an existing workbook that contains 36 worksheets. On the first worksheet he set up the footers the way that he wants. Ross wonders if there is an easy way to copy the footers from that first worksheet to all the other worksheets in the workbook.

It is very easy to do this in Excel. All you need to do is to follow these steps:

  1. Select your first worksheet, the one that has the headers and footers just the way you want.
  2. Now, in the worksheet tab area at the bottom of the Excel window, hold down the Shift key as you click on the tab for the last worksheet you want to affect. You've now created a selection set of worksheets, and your first worksheet should still be the active one. (You can tell this because it has the green underline on the tab itself.) (See Figure 1.)
  3. Figure 1. A selection set of worksheet tabs.

  4. Display the Page Layout tab of the ribbon.
  5. Click the small icon at the bottom-right of the Page Setup group. Excel displays the Page Setup dialog box.
  6. Make sure the Header/Footer tab is displayed. The headers and footers shown in the dialog box should reflect those of the active worksheet, which is the worksheet you first selected in step 1.
  7. Click OK. All of the worksheets you selected in step 2 are still selected.
  8. Click any worksheet tab other than the active one (the one that has the green underline). This cancels your selection set.

That's it; the headers and footers from the active worksheet are copied to all the worksheets you selected. Any previous headers and footers on the selected worksheets are overwritten in the process.

The key to success in these steps is to make sure that the active worksheet is the one that has your desired headers and footers. This is the worksheet that you should have selected in step 1 and the one that has the green underline on the worksheet tab, as described in step 2. It is that worksheet's headers and footers you should see on the Header/Footer tab of the Page Layout dialog box in step 5. (If you don't see the proper headers and footers in step 5, you should immediately press Esc or click on Cancel in the dialog box so you don't copy the headers and footers.)

If you want to only copy footers (and leave headers as they are, which Ross seems to desire), then you will need to resort to using a macro. Here's a simple macro that will handle any text in the footers only:

Sub CopyFooters()
    Dim wSource As Worksheet
    Dim sSourceName As String
    Dim bFP As Boolean
    Dim bEP As Boolean
    Dim wSFP As Object
    Dim wSEP As Object
    Dim w As Worksheet

    Set wSource = ActiveWorkbook.Worksheets("Sheet1")
    sSourceName = wSource.Name
    Set wSFP = wSource.PageSetup.FirstPage
    Set wSEP = wSource.PageSetup.EvenPage

    With wSource.PageSetup
        bFP = .DifferentFirstPageHeaderFooter
        bEP = .OddAndEvenPagesHeaderFooter
    End With

    For Each w In ActiveWorkbook.Worksheets
        With w.PageSetup
            .DifferentFirstPageHeaderFooter = bFP
            .OddAndEvenPagesHeaderFooter = bEP

            .LeftFooter = wSource.PageSetup.LeftFooter
            .CenterFooter = wSource.PageSetup.CenterFooter
            .RightFooter = wSource.PageSetup.RightFooter

            If bFP Then
                With .FirstPage
                    .LeftFooter.Text = wSFP.LeftFooter.Text
                    .CenterFooter.Text = wSFP.CenterFooter.Text
                    .RightFooter.Text = wSFP.RightFooter.Text
                End With
            End If

            If bEP Then
                With .EvenPage
                    .LeftFooter.Text = wSEP.LeftFooter.Text
                    .CenterFooter.Text = wSEP.CenterFooter.Text
                    .RightFooter.Text = wSEP.RightFooter.Text
                End With
            End If
        End With
    Next w
End Sub

If you examine the code closely, you'll note that there is a difference in how the footer contents are referenced based on whether the footer is a regular footer, a first-page footer, or an even-page footer. Specifically, the non-regular footers use the .Text property, whereas the regular footers don't. This is because (apparently) VBA defaults to using the .Text property when you are using the .LeftFooter, .CenterFooter, and .RightFooter properties of the .PageSetup object. However, if you use those same footer properties with either the .FirstPage or .EvenPage objects, then the .Text property is not assumed—it must be specifically stated. Without it being specified as shown here, the macro will crash.

If you want to use the macro, all you need to do is to make sure the "Sheet1" reference is changed to the name of the worksheet from which you want to copy the footers.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13902) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Technique for Adding a Text Box to an Envelope

Text boxes can be a great design feature to use in laying out a document. You may want to add one to an envelope, ...

Discover More

Looking Up Antonyms

Antonyms are words that have opposite meanings. The grammar tools available in Word can suggest antonyms for some words. ...

Discover More

Ignoring Other Applications

Do you want Excel to ignore other applications that may be running on your computer? You can configure the program to do ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Specifying the Y Value in X of Y Page Numbering

Page numbers in Excel headers and footers have always been a source of frustration for users. This tip recounts one ...

Discover More

Date Last Edited

When adding headers or footers to your worksheets, you may want to include the date that the workbook was last edited. ...

Discover More

Moving Part of a Footer Down a Line

Setting up a single footer line for your printouts is fairly easy. If you want to move part of the footer down a line so ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 8?

2023-07-19 09:54:25

J. Woolley

My Excel Toolbox includes the following function to put Text in a worksheet's headers or footers, which makes them dynamic instead of static:
=SetHeaderFooter(H_F,L_C_R,Text,[FirstPage],[EvenPages],[Target])
For a complete description of this function, see
https://excelribbon.tips.net/T000559_Using_a_Formula_in_a_Footer.html
For additional discussion, see my comments here:
https://excelribbon.tips.net/T011099_Last_Saved_Date_in_a_Footer.html
https://excelribbon.tips.net/T007990_Specifying_Date_Formats_in_Headers.html
https://excelribbon.tips.net/T011649_Showing_Filter_Criteria_on_a_Printout.html
Also, see https://sites.google.com/view/MyExcelToolbox


2023-07-17 13:50:35

J. Woolley

@Shadeburst
After further consideration, perhaps you were referring to variable names in the Tip's macro instead of the version I posted below. Nevertheless, my most recent comment is still valid.


2023-07-17 10:38:47

J. Woolley

@Shadeburst
Here is one excuse for using variable names like bFP: When posting VBA to the Tips site, long variable names will cause statements to wrap to the next line, which makes them difficult to read. It is not easy to know where the statement will wrap because the font is not a fixed size (like Courier). I avoid more than 80 characters per line. And it is desirable to minimize the number of lines posted.
It is common (but not necessary) to use "b" as the first character for a Boolean variable or "s" for a String, etc. I chose bFP instead of bFirstPage. Maybe you can guess what bEP and the other variables represent.


2023-07-17 02:19:57

Shadeburst

When I first started writing code, the Apple IIe had twin 5.25" floppy disk drives each with a capacity of 140k formatted. Microsoft Basic was designed for economy and a variable name was restricted to a single letter. This made debugging your own code difficult, never mind someone else's.

Enter the IBM-PC with disk capacity in the megabytes and programming languages like Turbo Pascal that allowed variable names of any length. There may have been a limit of 256 characters, but get serious. Quickly coders learned to make code self-commenting by assigning meaningful names to variables and subroutines.

There is no excuse for using cryptic variable names like bFP, unless it is your intention to confuse.

That apart, this macro has taught me a lot about page properties and how to access them. Thank you.


2023-07-15 10:54:18

J. Woolley

The Tip's macro unnecessarily copies footers from Sheet1 to Sheet1 (itself). Also, it should be noted that Sheet1 might not be first in the workbook's arrangement of sheet Tabs. If Ross wants to copy from the worksheet with the first Tab, here is a more efficient version of the Tip's macro:

Sub CopyFooters2() 'ignore FooterPictures
    Dim PS0 As PageSetup, PS1 As Object, PS2 As Object
    Dim bFP As Boolean, bEP As Boolean, n As Integer
    With Worksheets(1) 'copy from first worksheet Tab
        Set PS0 = .PageSetup
        With PS0
            bFP = .DifferentFirstPageHeaderFooter
            If bFP Then Set PS1 = .FirstPage
            bEP = .OddAndEvenPagesHeaderFooter
            If bEP Then Set PS2 = .EvenPage
        End With
    End With
    For n = 2 To Worksheets.Count 'copy to other worksheets
        With Worksheets(n).PageSetup
            .LeftFooter = PS0.LeftFooter
            .CenterFooter = PS0.CenterFooter
            .RightFooter = PS0.RightFooter
            .DifferentFirstPageHeaderFooter = bFP
            .OddAndEvenPagesHeaderFooter = bEP
            If bFP Then
             With .FirstPage
                    .LeftFooter.Text = PS1.LeftFooter.Text
                    .CenterFooter.Text = PS1.CenterFooter.Text
                    .RightFooter.Text = PS1.RightFooter.Text
                End With
            End If
            If bEP Then
                With .EvenPage
                    .LeftFooter.Text = PS2.LeftFooter.Text
                    .CenterFooter.Text = PS2.CenterFooter.Text
                    .RightFooter.Text = PS2.RightFooter.Text
                End With
            End If
        End With
    Next n
End Sub

Both macros ignore any Left/Center/RightFooterPicture (&[Picture]) as well as any chart sheets. To include chart sheets, substitute Sheets in place of Worksheets; there are 3 instances (ignoring comments). To copy headers instead of footers, substitute Header in place of Footer everywhere EXCEPT DifferentFirstPageHeaderFooter and OddAndEvenPagesHeaderFooter; there are 19 instances (ignoring comments).


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.