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.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
You can easily create headers and footers for multiple worksheets by working with a selection set of the worksheets you ...Discover More
Page numbers in Excel printouts are typically simple counters, without much chance for embellishment. If you want to add ...Discover More
Referencing information between cells in a worksheet is a piece of cake using some elemental formulas. You cannot, ...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.