はじめに
Excelでシステム日付を西暦日付表示に変換する必要がったので、マクロを実装しました
マクロ実行前のデータ
マクロ実行前のデータ画像は下記の通りです
実装したマクロ
実装したマクロのソースコードです。
Sub change_date()
'システム日付変数の定義
Dim date_data As Variant
'西暦日付変数
Dim ans_date As Date
'ワークシートオブジェクト変数
Dim ws As Worksheet
'ws変数の定義セット
Set ws = ThisWorkbook.Worksheets("Sheet1")
'カウント変数
Dim i As Long
'データの最終行を取得
Dim end_row_num As Long
end_row_num = ws.Cells(Rows.Count, 4).End(xlUp).Row
'ループで回して西暦に変換する
For i = 4 To end_row_num
date_data = ws.Cells(i, 4)
ans_date = DateSerial(1900, 1, 1) + date_data - 2
ws.Cells(i, 5).Value = ans_date
Next i
End Sub
実行結果
実行結果は下記の画像です。
最後に
シリアル日付の変換について記事にしました。