Skip to content

Instantly share code, notes, and snippets.

@Shinichi-Ohki
Last active December 28, 2015 16:39
Show Gist options
  • Save Shinichi-Ohki/7530057 to your computer and use it in GitHub Desktop.
Save Shinichi-Ohki/7530057 to your computer and use it in GitHub Desktop.
ハイフンなし郵便番号をハイフンありにする式。Google Spredsheetで動いたけど多分ExcelやOpenOffice.org Clacでも動くんじゃないかな。 ハイフンなし郵便番号が数値でも文字列でも大丈夫。
=if(isblank(A1)=TRUE,"",if(ISNUMBER(A1),TEXT( int(A1/10000),"000")&"-"&text(mod(A1,10000),"0000"),left(A1,3)&"-"&right(A1,4)))
@Shinichi-Ohki
Copy link
Author

北海道の郵便番号が0から始まるのに数値だとその0が消えてしまって郵便番号にならなくなってしまうので文字列にするのです。それに対応したのが今回の式です。
なお「'0xxnnnn」のように先頭にシングルクォートを入れると表計算ソフトが文字列として処理してくれますよ。
この式はA1セルを参照しているので、適当なところに変えてください。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment