Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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: Putting a Different Date in a Header.
by Allen Wyatt
(last updated July 25, 2015)
Adding the current date to the header of a worksheet is easy—Excel provides a dialog box where you can specify the placement of the date and use the '&[date]' coding to actually insert the date. But what if you want to insert yesterday's date or tomorrow's date into the header?
That's not nearly as easy. In fact, you can't do it without using a macro. Perhaps the most flexible approach is to write the macro so that it updates the date just before the worksheet is printed, as shown in the following:
Private Sub Workbook_BeforePrint(Cancel As Boolean) ActiveSheet.PageSetup.CenterHeader = _ Format(Date - 1, "mmmm d, yyyy") End Sub
The macro places yesterday's date into the center of the header; you can easily change the CenterHeader property of one of the other available header locations (LeftHeader or RightHeader). You can also change the macro to insert tomorrow's date by changing the "- 1" to "+ 1".
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10678) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Putting a Different Date in a Header.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
When printing a worksheet, you may want to have the footer different on the first page of your document than it is on ...Discover More
When printing out a worksheet, you may want Excel to include, in the footer, the date the data was last saved. There is ...Discover More
You can easily create headers and footers for multiple worksheets by working with a selection set of the worksheets you ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.