2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【VBA】システム日付を西暦日付表示に変換する

Posted at

はじめに

Excelでシステム日付を西暦日付表示に変換する必要がったので、マクロを実装しました

マクロ実行前のデータ

マクロ実行前のデータ画像は下記の通りです

test1.jpg

実装したマクロ

実装したマクロのソースコードです。

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

実行結果

実行結果は下記の画像です。

test2.jpg

最後に

シリアル日付の変換について記事にしました。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?