vba VBA获取上一个工作日的日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43898970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:34:30  来源:igfitidea点击:

VBA to get the date of the Previous Workday

vbaexcel-vbaexcel

提问by MMS

I am trying to get the Previous working day of today. Say if suppose today is Wednesday, then the previous working day will be Tueday but if today is Monday then the previous working day will be Friday. How do I get the date of the previous working day?

我正在尝试获取今天的上一个工作日。假设今天是星期三,那么前一个工作日将是星期二,但如果今天是星期一,那么前一个工作日将是星期五。如何获取前一个工作日的日期?

Thanks

谢谢

回答by Gary's Student

Consider:

考虑:

=WORKDAY(TODAY(),-1)

enter image description here

在此处输入图片说明

This formula can be easily modified to handle holidays.

可以轻松修改此公式以处理假期。

In VBA:

在 VBA 中:

Sub dural()
    MsgBox CDate(Evaluate("WORKDAY(TODAY(),-1)"))
End Sub

回答by SuShuang

It's worth to say that this function can handle also Public Holidays, but this argument is optional. So in fact we have:

值得一提的是,这个函数也可以处理公共假期,但这个参数是可选的。所以实际上我们有:

=WORKDAY(TODAY(),-1, 'Range with Public Holidays Dates')

for example:

例如:

=WORKDAY(TODAY(),-1, A1:A10)