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 1 year has passed since last update.

エクセルでKB/MB/GBとか表示させたい

Posted at

やりたいこと

エクセルで、数値をKB/MB(キロバイト/メガバイト)で表示させたい。
↓こんな。

1024 -> 1KB
1.5*1024*1024 -> 1.5MB

結論

A1に変換前の数値が入ってるとして。

=ROUND(A1/POWER(1024, INT(LOG(A1,1024))), 2) &
IF(INT(LOG(A1,1024))=0, "", MID("KMGTPE", INT(LOG(A1,1024)),1))&
"B"

実行例

excel_kb.png

解説

MID("KMGTPE"

ここが肝です。
1024のlogとったヤツをindexにして、"KMGTPE"の文字配列から引いてくるイメージです。
つまり、E=エクサまでしか対応してないです。適当に追加してください。


もっと簡単にできる方法あれば教えてください。

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?