|
こんばんは
↓のような感じですかね?
アレンジしてみてください
Sub D_CNT()
Dim ws As Worksheet
Dim SDate As String
Dim WName As String
Dim TDate As Date
Dim TD As Integer
Dim WD As Integer
Dim WC As Integer
Dim CNT As Integer
Dim i As Integer
Set ws = ThisWorkbook.Worksheets("Sheet1")
SDate = ws.Range("A1").Text
If SDate = "" Then
MsgBox "NODATA"
Exit Sub
End If
If InStr(SDate, "土曜") <> 0 Then
WD = 7
i = InStr(SDate, "土曜")
ElseIf InStr(SDate, "日曜") <> 0 Then
WD = 1
i = InStr(SDate, "日曜")
Else
MsgBox "DATA ERROR"
Exit Sub
End If
WC = CInt(Mid(SDate, i - 1, 1))
If WC < 1 Or WC > 5 Then
MsgBox "DATA ERROR"
Exit Sub
End If
TDate = DateSerial(Year(Date), Month(Date), 1)
TD = Weekday(TDate)
If WD > TD Then
CNT = WD - TD
ElseIf WD < TD Then
CNT = WD + 7 - TD
Else
CNT = 0
End If
CNT = CNT + (WC - 1) * 7
TDate = DateAdd("d", CNT, TDate)
ws.Range("B1") = TDate
End Sub
|
|