ばくがの業務効率化チャンネル

このブログは個人的なエクセルの備忘録です

VBAで日時と曜日を取得してセルに書き込む

Sub 日時の取得()

'変数宣言
Dim 本日 As Date
Dim 期限日 As Date
Dim 行番号 As Long

'本日の日付を取得
    本日 = Date

'期限日は本日から14日後
    期限日 = 本日 + 14

'対象は1列目の最終行まで
        For 行番号 = 2 To Cells(Rows.Count, 1).End(xlUp).Row

            '期限日
            Cells(行番号, 4) = 期限日
            '期限日の日のみ
            Cells(行番号, 5) = Day(期限日)
            '期限日の月のみ
            Cells(行番号, 6) = Month(期限日)
            '期限日の曜日のみ
            Cells(行番号, 7) = WeekdayName(Weekday(期限日), True)
      
        Next 行番号

End Sub