|
どなたか教えてください。
第○○曜日とセルに書いてあるデータを今月の日付に書き換えたいのですが、
行き詰まっています。
例えば
第3土曜 なら⇒ 2006/6/17
第3日曜 なら⇒ 2006/6/18
としたいのです。
プログラムを書いてみましたが、これでは何曜日という事と、土日の第○週というカウント
だけしか得られず、どう修正してよいか困っています。
Sub Main()
Dim yobi As Integer '曜日コード
Dim hi As Date '日付
Dim sta_cnt as integer '土曜○週
Dim sun_cnt as integer ’日曜○週
Dim cur_stdate As Date '初日
Dim sd As Integer
Dim cur_eddate As Date '月末
Dim ed As Integer
Dim lp As Integer 'ループ
cur_date = DateSerial(Year(Date), Month(Date), 1) '現在の月の初日
sd = Day(cur_date)
cur_eddate = DateSerial(Year(Date), Month(Date) + 1, 0) '現在の月の最後
ed = Day(cur_eddate)
For lp = sd To ed
hi = DateSerial(Year(Date), Month(Date), lp) '現在の月の初日
yobi = Format(hi, "w")
Debug.Print "yobi="; yobi
If yobi = 7 Then
sta_cnt = sta_cnt + 1
ElseIf yobi = 1 Then
sun_cnt = sun_cnt + 1
End If
Next
end sub
どなたか教えてください宜しくお願いいたします。
|
|