在VBA中显示工作日和非周日的代码

时间:2016-10-28 04:51:18

标签: vba

Sub wd()
Dim Isweekday As Boolean
Select Case Weekday(A3, vbSaturday)
Case 1 To 2
Isweekday = False
Case Else
Isweekday = True
End Select
Range("A4").Value = Isweekday
End Sub

这段代码有什么不对吗?...我希望工作日显示为true而非工作日显示为false

1 个答案:

答案 0 :(得分:1)

您的代码将A3视为未声明的变量。

Select Case Weekday(Range("A3").Value, vbSaturday)

更短的:

Sub wd()
    Range("A4").Value = (Weekday(Range("A3").Value, vbSaturday) > 2)
End Sub