Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Specifying Date Formats in Headers.
Written by Allen Wyatt (last updated October 7, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
Normally, the dates used by Excel in headers and footers (with the [DATE] code) are based on the regional settings controlled by Windows. Thus, if your local settings show the date in a specific format in Windows itself, that is the same format that Excel will use in headers and footers.
This can be a drawback if you are required to maintain a certain type of system date format for compatibility with other systems in your office, but you need to use a different date format in the header or footer of a specific worksheet. The only way around this problem is to either change the regional settings within Windows, or revert to using a macro to set the appropriate area of your header or footer.
For instance, let's say you wanted to set the right header equal to the current date in the format m/d/yy. To do that, you can use a very simple macro, such as the following:
Sub HeaderDate() ActiveSheet.PageSetup.RightHeader = Format(Date, "m/d/yy") End Sub
To use this, simply run it and it adds the date, in the specified format, into the right section of the header. If you want the information added to a different place in the footer or header, you simply replace the RightHeader portion of the macro with one of the following: LeftFooter, CenterFooter, RightFooter, LeftHeader, or CenterHeader.
To change the format in which the date is added, simply change the format used in the Format function. There are all sorts of patterns you can use for the date; check the online Help system for information about the Format function in VBA.
You should note that dates added to headers or footers in this manner are not dynamic, as is the result of the [DATE] code. When you use the macro to insert the date, it is inserted as a text string. If you later want to change the date to something else (like the then-current date), you will need to rerun the macro.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7990) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Specifying Date Formats in Headers.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Add an ampersand to the text in a header or footer and you may be surprised that the ampersand disappears on your ...
Discover MoreExcel allows you to create headers and footers. In this tip you discover that the headers and footers in Excel may not be ...
Discover MoreToday's date is easy to add to a header, but what if you want to add a date that is adjusted in some manner? Adding ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-10-07 10:32:18
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])
See https://excelribbon.tips.net/T000559_Using_a_Formula_in_a_Footer.html for a complete description. Note that Text must not directly reference a volatile function like TODAY(), but indirect reference is OK.
Assume cell $A$1 contains the following formula:
=TEXT(TODAY(),"m/d/yy")
Then this formula will set the right header with today's date in the preferred format:
=SetHeaderFooter("header","right",$A$1)
See https://sites.google.com/view/MyExcelToolbox
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