利用VBA求每月首个工作日代码
发布日期:2015-03-18浏览:3725
Private Sub CommandButton1_Click()
Dim yy, mm, dd
yy = Range("b1")
'对12个月进行循环
For m = 4 To 15
mm = Cells(m, 1)
For dd = 1 To 5
If Weekday(yy & "-" & mm & "-" & dd) = 1 Or Weekday(yy & "-" & mm & "-" & dd) = 7 Then
Else
Cells(m, 2) = yy & "-" & mm & "-" & dd
Exit For
End If
Next dd
Range("d2").AddComment
Next m
End Sub
Dim yy, mm, dd
yy = Range("b1")
'对12个月进行循环
For m = 4 To 15
mm = Cells(m, 1)
For dd = 1 To 5
If Weekday(yy & "-" & mm & "-" & dd) = 1 Or Weekday(yy & "-" & mm & "-" & dd) = 7 Then
Else
Cells(m, 2) = yy & "-" & mm & "-" & dd
Exit For
End If
Next dd
Range("d2").AddComment
Next m
End Sub