How can I format bytes a cell in Excel as KB, MB, GB etc?
Here is one that I have been using: -
[<1000000]0.00," KB";[<1000000000]0.00,," MB";0.00,,," GB"
Seems to work fine.
The above formatting approach works but only for three levels. The above used KB, MB, and GB. Here I've expanded it to six. Right-click on the cell(s) and select Format Cells. Under the Number tab, select Custom. Then in the Type: box, put the following:
[<1000]##0.00" B";[<1000000]##0.00," KB";##0.00,," MB"
Then select OK. This covers B, KB, and MB. Then, with the same cells selected, click Home ribbon, Conditional Formatting, New Rule. Select Format only cells that contain. Then below in the rule description, Format only cells with, Cell Value, greater than or equal to, 1000000000 (that's 9 zeros.) Then click on Format, Number tab, Custom, and in the Type: box, put the following:
[<1000000000000]##0.00,,," GB";[<1000000000000000]##0.00,,,," TB";#,##0.00,,,,," PB"
Select OK, and OK. This conditional formatting will take over only if the value is bigger than 1,000,000,000. And it will take care of the GB, TB, and PB ranges.
567.00 B
5.67 KB
56.70 KB
567.00 KB
5.67 MB
56.70 MB
567.00 MB
5.67 GB
56.70 GB
567.00 GB
5.67 TB
56.70 TB
567.00 TB
5.67 PB
56.70 PB
Anything bigger than PB will just show up as a bigger PB, e.g. 56,700 PB. You could add another conditional formatting to handle even bigger values, EB, and so on.
Though Excel format conditions will only display 1 of 3 conditions related to number size (they code it as "positive; negative; zero; text" but I prefer to see it as : if isnumber and true; elseif isnumber and false; elseif number; elseif is text )
so to me the best answer is David's as well as Grastveit's comment for other regional format.
Here are the ones I use depending on reports I make.
[<1000000]#,##0.00," KB";[<1000000000]#,##0.00,," MB";#,##0.00,,," GB"
[>999999999999]#,##0.00,,,," TB";[>999999999]#,##0.00,,," GB";#.##0.00,," MB"
[<1000000]# ##0,00 " KB";[<1000000000]# ##0,00 " MB";# ##0,00 " GB"
[>999999999999]# ##0,00 " TB";[>999999999]# ##0,00 " GB";# ##0,00 " MB"
Take your pick!
You can't really do calculations in the formatting features of Excel. You can use something like the following to do a rough estimation though:
[<500000]#,##0" B";[<500000000]#,##0,," MB";#,##0,,," GB"