vba 工作日功能添加工作日

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28749349/
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 06:22:07  来源:igfitidea点击:

Workday Function to add Workdays

vbaexcel-vbafunctionexcel

提问by New2VBA

I'm trying to run code based off of dates in the D column. The code below works. But the "if" part of the conditional formatting needs to be + 30 workdays, not plus thirty days. I'm assuming that the WORKDAY function helps with this. But when I try + workday(30) and things like that, I don't get anywhere.

我正在尝试根据 D 列中的日期运行代码。下面的代码有效。但是条件格式的“if”部分需要 + 30 个工作日,而不是加上 30 天。我假设 WORKDAY 函数对此有所帮助。但是当我尝试 + workday(30) 之类的事情时,我一无所获。

For Each oKey In oDictionary.keys
    Editing_Sheet.Range("A1").CurrentRegion.AutoFilter Field:=1,    Criteria1:=CStr(oKey)
    LastRowFiltered = Editing_Sheet.Cells(Rows.Count, "A").End(xlUp).Row
        If Range("D" & LastRowFiltered) <= Date + 30 Then
         'run code'

回答by Gary's Student

To use the worksheet Workday()function within VBA:

要在VBA 中使用工作表Workday()函数

Sub WhyWork()
    Dim d1 As Date, wf As WorksheetFunction
    Set wf = Application.WorksheetFunction
    d2 = wf.WorkDay(Date, 30)
    MsgBox Date & vbCrLf & d2
End Sub