Thread: Macro for Dates
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
isabelle isabelle is offline
external usenet poster
 
Posts: 587
Default Macro for Dates

to adjust date format in different language

Dim FirstDay As Date, LastDay As Date
Dim sFirstDay As String, sLastDay As String

FirstDay = DateSerial(Year(Now), Month(Now) - 1, 1)
LastDay = DateSerial(Year(Now), Month(Now) - 1,
Day(DateSerial(Year(Now), Month(Now), 1 - 1)))

sFirstDay = Format(FirstDay, "mm/dd/yyyy")
sLastDay = Format(LastDay, "mm/dd/yyyy")

With ActiveSheet.PageSetup
.LeftHeader = "Date Range: " & sFirstDay & " - " & sLastDay
End With

isabelle

Le 2013-11-06 18:26, isabelle a écrit :
hi JCO,

Dim firstDay As Date, lastDay As Date

firstDay = DateSerial(Year(Now), Month(Now) - 1, 1)
lastDay = DateSerial(Year(Now), Month(Now) - 1,
Day(DateSerial(Year(Now), Month(Now), 1 - 1)))

With ActiveSheet.PageSetup
.LeftHeader = "Date Range: " & firstDay & " - " & lastDay
End With

isabelle

Le 2013-11-05 19:02, JCO a écrit :
I have a report that requires the current date in the right header and
the date range in left header. The date range is the first day of the
previous month to the last day of the previous month.

Example: Today is 11/05/2013. As I run the macro, it should look like
below:
Date Range: 10/01/2013 - 10/31/2013 Date:
11/05/2013

Thanks