Using a Formula in a Footer

Written by Allen Wyatt (last updated May 25, 2026)

3

Skye has three cells on a worksheet that are important. One cell contains a start date, the second contains an ending date, and the third contains a total for the transactions between those dates. He would like to have a footer for the printed page that incorporates these three pieces of data, dynamically. He wonders if there is a way to get a formula into the footer so it can reflect these values.

There is no built-in way to do this in Excel because formulas cannot be entered into footers; they aren't recognized as formulas by the program. You can, however, use a macro to set your footer. Let's assume, for the sake of this approach, that your start date is contained in cell E1, your ending date is in cell E2, and your total of transactions are in cell E3. In that case, you could use a macro like this:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim sTemp As String

    With Worksheets("Sheet1")
        ' Set wording for date range
        sTemp = .Range("E1").Text & " through " & .Range("E2").Text
        sTemp = sTemp & " (" & .Range("E3").Text & ")"
        .PageSetup.CenterFooter = sTemp
    End With
End Sub

There are a few things to note in this macro. First of all, the macro only sets the footer information in the worksheet named Sheet1, though you can change this worksheet name to whatever you need. Second, notice that the .Text property is used instead of the .Value property. There are actually three ways you could reference the cell contents, as shown here:

sTemp = Worksheets("Sheet1").Range("E1")
sTemp = Worksheets("Sheet1").Range("E1").Value
sTemp = Worksheets("Sheet1").Range("E1").Text

The first two approaches are equivalent; they set sTemp equal to the contents of the cell. The third approach is different; it sets sTemp equal to the formatted text of the cell. In other words, sTemp will be equal to whatever is in cell E1, as it is formatted in the cell. Since you are working with dates and sums, this is the approach you want to use, so it is what was used in the macro.

Third, the macro ends up setting up the footer in the sTemp variable. As written, the macro would create a footer that looked similar to this:

1 Jul 2022 through 15 Jul 2022 ($1,234.56)

Again, the actual appearance depends on the formatting in cells E1, E2, and E3. The macro adds the word "through" and puts parentheses around the sum of transactions. You can modify these additional elements directly within the macro.

Fourth, the macro assigns the formatted sTemp string (your footer) to the center position in the page footer for the worksheet. If you prefer for the footer to be elsewhere, you can simply change the .CenterFooter property to either .LeftFooter or .RightFooter.

Finally, you need to be aware that this macro is designed to be added to the ThisWorkbook module. It is run, automatically, just before the workbook is printed. It is not triggered, however, by looking at the worksheet in Print Preview, so you can't count on what you may see before you actually print.

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 (559) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365.

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

Headings On Your Printout

If you've got a table that spans multiple printed pages, you probably want to repeat a row or two of that table as a ...

Discover More

Referencing a Worksheet Name

Excel provides ways to reference the column or row number of a cell, but it doesn't provide a built-in way to reference a ...

Discover More

Generating Unique, Sequential Names

Do you need to create a number of words or phrases where you only alter a few letters in each one? If the alterations ...

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Sequential Page Numbers Across Worksheets

How do you want your page numbers to appear on your printed worksheets? Chances are good that you want them to be ...

Discover More

Using a Custom Date Format in a Header or Footer

Need to show a custom date in the header or footer of a printout? You'll need to resort to using a macro, as described in ...

Discover More

Adding Ampersands in Headers and Footers

Add an ampersand to the text in a header or footer and you may be surprised that the ampersand disappears on your ...

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 four more than 7?

2026-05-25 05:45:03

Kiwerry

Thanks for another interesting read, AllennI found the .Value versus .Text information interesting, copied your three "sTemp" lines into a temporary macro, adding a n: debug.print sTempnto each line and tried them out . The results may be of use to some readers.nAs you said, the first two yield identical results, but those results were influenced by the cell formatting to some extent:nnThey both yielded 44063 for a cell containing the number 44063, where the cell format was General;nThe .Text form yielded 44063 for this cell as well.nnThey both yielded 20/08/2020 for a cell containing the number 44063, where the cell format was a short Date format;nThe.Text form yielded 20/08/2020 for this cell as well.nnThe difference became apparent when the following custom format was used for a cell containing the number 44063: [$-de-DE]ddd, d mmm yyyynThe first two variations yielded 20/08/2020 for this cell as well, BUTnthe .Text form yielded Do, 20 Aug 2020nnMy conclusions were nthat the first two forms yield the same results, but that these are not completely independent of cell formatting, andnthat the use of the .Text form is essential in cases where cells with custom formatting may be encountered and the displayed form of the cells is wanted, rather than the cell value.


2022-09-04 16:06:59

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:n=SetHeaderFooter(H_F,L_C_R,Text,[FirstPage],[EvenPages],[Target])nThe first character of H_F must be H for header or F for footer (alphabetic case ignored).nThe first character of L_C_R must be L for left or C for center or R for right (case ignored).nText must NOT directly reference a volatile function, but indirect reference is OK. Ampersand (&) followed by P, N, D, T, Z, F, or A (case ignored) represents Page, Pages, Date, Time, Path, File, or Tab; otherwise, ampersand (&) will be doubled (&&). The first 255 characters of Text apply.nFirstPage default is FALSE; if TRUE and NOT EvenPages and 'Different first page' (manual), first page header/footer applies.nEvenPages default is FALSE; if TRUE and NOT FirstPage and 'Different odd and even pages' (manual), even pages header/footer applies.nTarget identifies the target worksheet. It can be a cell or range on any worksheet in an open workbook; if omitted, the formula's worksheet is assumed.nThe function returns text indicating the result or #VALUE!... indicating invalid argument(s). Avoid multiple formulas referring to the same header/footer.nHere is a cell formula for the Tip's example:n=SetHeaderFooter("foot","center",E1&" through "&E2&" ("&E3&")")nSee https://sites.google.com/view/MyExcelToolbox


2022-08-13 11:28:13

Brian Lair

Very helpful tip! I especially found the .Value vs. .Text info enlightening. Cheers!


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.