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.
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!
Ever wish that you could create nice, long footers that appear at the bottom of each page when you print your worksheet? ...Discover More
Referencing information between cells in a worksheet is a piece of cake using some elemental formulas. You cannot, ...Discover More
When you have a worksheet that includes a long list of names, you may want the first and last names on each page to ...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.