1
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?

Excel VBAで文字列の西暦から和暦に変換したい

Posted at

1. はじめに

  • Excel VBAで文字列の西暦を和暦に変換したい
  • 元号が変更になっても対応できるようにしたい

2. 開発環境

  • VBA
  • Excel 2021

3. サンプルソース

  • Formatで形式をggge年m月を指定する
Module1
Public Sub EditGGGGEM()

    ' 西暦→和暦を編集
    With ThisWorkbook.Sheets("Sheet1")
        .Cells(2, 2).Value = Format(Left(.Cells(2, 1).Value, 4) & "/" & Mid(.Cells(2, 1).Value, 5), "ggge年m月")  ' 西暦→和暦
    End With

End Sub

4. 実行結果

  • 令和の場合
    image.png

  • 平成の場合
    image.png

  • 昭和の場合
    image.png

5. 参考文献

1
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
1
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?