Header that auto displays the previous month

Stuck1

Board Regular
Joined
Sep 3, 2009
Messages
73
Hi all,

I want to display the text: "Period Report to: December 2009" on the print out of a report I produce every month. I always publish the report at the start of the following month, so December's report will come out in January and January's in Fenruary, etc.

I know I could change the headers every month, but I always forget to do it. I have this code, but don;t know how to get it to say the previous month instead of today's date:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet.PageSetup
.RightHeader = "& Period Report to: " & Format(Now, "DD-MMM-YY")
End With
End Sub

Any help would be great.

Thanks,

Lee
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this:

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet.PageSetup
.RightHeader = "& Period Report to: " & Format(DateAdd("m", -1, Date), "mmmm")
End With
End Sub
 
Upvote 0
or
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    ActiveSheet.PageSetup.RightHeader = "& Period Report to: " & Format(Date-28, "mmmm yyyy")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,345
Messages
6,124,408
Members
449,157
Latest member
mytux

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top