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?

Excelでセル先頭のシングルクォーテーションを一括削除

Posted at

やりたいこと

Excelで「'000123」と入力されたセルからシングルクオーテーションを削除し、文字列「000123」に変換したい。

試したこと

以下の方法を試したが、シングルクォーテーションを削除できなかった。

range("A1").value = range("A1").value
range("A1").value = range("A1").value2
range("A1").value = range("A1").text
Replace(range("A1").value, Chr(39), "")
Replace(range("A1").value2, Chr(39), "")
Replace(range("A1").text, Chr(39), "")

数値(「123」)には変換できるものの、その後Format関数で「000123」に戻そうとすると、再びシングルクォーテーションが復活してしまう。

PrefixCharacterプロパティについて

PrefixCharacterプロパティを使用すると、シングルクォーテーションの有無を取得できるが、読み取り専用のため変更はできなかった。
PrefixCharacterプロパティ

解決策

セルの書式をクリアすると、シングルクォーテーションが削除され、見た目どおりの「000123」の文字列として扱うことができる。(拍子抜け:rolling_eyes:
書式クリア後に数値⇔文字列の操作をしてもシングルクオーテーションが復活することもなかった。

range("A1").ClearFormats
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?