上一个星期一的Excel的日期 [英] Date for Previous Monday Excel
问题描述
今天是今天的02/27/2013。
我需要公式,这将返回上一个星期一的日期。这将是(02/17/2013)
我需要这样我可以使用文件名称或电子邮件主题在我发送电子邮件的vba代码中。
使用oMail
'取消将以下行注释为硬代码收件人
.To =myemail@email.com
'取消注释下面的行以硬编码主题
.Subject =当前报告
.Attachments.Add WB .FullName
.Display
结束
公共功能LastMonday(pdat As Date)As Date
LastMonday = DateAdd(ww,-1,pdat - (Weekday(pdat,vbMonday) - 1))
结束功能
工作日(yourdate,vbMonday)返回1为星期一,2为星期二等等,所以
pdat - (工作日(pdat,vbMonday) - 1)
将给我们最近的星期一减去工作日( )-1从传递的日期开始的天数
DateAdd(ww,-1,...)
从该日起减去一周。
LastMonday(cdate(2/27/13))
返回2/18/2013(这是星期一,而不是第17)
Today is 02/27/2013 which is Wensday. I need formula which will return me date for previous Monday.which would be (02/17/2013)
I need to so I can use for file name or email subject in my vba code which sends emails.
With oMail
'Uncomment the line below to hard code a recipient
.To = "myemail@email.com"
'Uncomment the line below to hard code a subject
.Subject = "Current Report"
.Attachments.Add WB.FullName
.Display
End With
Public Function LastMonday(pdat As Date) As Date
LastMonday = DateAdd("ww", -1, pdat - (Weekday(pdat, vbMonday) - 1))
End Function
Weekday(yourdate, vbMonday) returns a 1 for Monday, 2 for Tuesday, etc. so
pdat - (Weekday(pdat, vbMonday) - 1)
Will give us the most recent Monday by subtracting the Weekday()-1 # of days from the passed date.
DateAdd("ww", -1, ...)
subtracts one week from that date.
LastMonday(cdate("2/27/13"))
Returns 2/18/2013 (which is Monday, not the 17th)
这篇关于上一个星期一的Excel的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!