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?

More than 1 year has passed since last update.

Excel VBA 和暦を設定したセルに日付を代入する場合、1年少なく表示される場合がある

Posted at

再現困難

再現は困難だが、修復はすべてクリアで書式をすべてクリアし、再度設定すると、いったん解消された。

セル表示形式

[$-ja-JP]ggge"年"m"月"d"日"

書式

横 均等割り付け(インデント0)
縦 中央揃え

VBA

activecell = #03/15/2024#

本来はべつのセルに入っている日付を代入する

通常の結果

image.png
令和6年3月15日

実際に起きた結果

image.png
令和5年3月15日

なぜか1年少なく表示された。
しかし中身は2024/3/15つまり令和6年3月15日である。

解決方法(上級者向け)

  1. 現在設定されている書式、セル幅、セルの高さ、フォント、フォントのサイズなど、必要な書式をメモする。
  2. 当然条件付き書式のようなものも記録する
  3. すべてクリアによって書式を消去
  4. 記録した書式設定等を再度設定する

原因

 そもそも1年少なく表示させる設定が思いつかない。
とにかく設定を確認してマクロを実行するだけではなく、実際の表示結果を確認する必要もあるということが分かった。

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?