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
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:
Figure 1. A selection set of worksheet tabs.
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:
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.
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!
Page numbers in Excel headers and footers have always been a source of frustration for users. This tip recounts one ...
Discover MoreWhen adding headers or footers to your worksheets, you may want to include the date that the workbook was last edited. ...
Discover MoreSetting 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 MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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).
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments