0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【VBA】日付が和暦のCSVデータを読み込む方法

Posted at

VBAを使ってCSVファイルのデータを読み込む時、日付が和暦の場合はそのまま読み込んでも文字列として認識されてしまいます。

【読み込み対象のCSVファイルの例】

"年月日(和暦)","お引出し","お預入れ","お取り扱い内容","残高"
R02.02.10,,80000,"振込 ジドウテアテ",99999999
R02.02.17,,30,"普通預金利息",99999999
R02.06.10,,80000,"振込 ジドウテアテ",99999999

【上記CSVファイルをエクセルで開いた結果】
image.png

これは、文字列として読み込まれているのかと思っていたのですが、セルの書籍設定を確認してみると以下のような設定に自動変換されていました。

image.png

つまり、文字列ではなく和暦として認識されているのです。

そのため、以下のようにセルの書籍設定を変更するだけで西暦表記に変換することができます。

【ユーザー定義として指定した場合】
image.png

【日付として指定した場合】
image.png

【結果】
image.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?