Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carrgilson/a3d243985ed4a118ca045d43a76d9649 to your computer and use it in GitHub Desktop.
Save carrgilson/a3d243985ed4a118ca045d43a76d9649 to your computer and use it in GitHub Desktop.
Microsoft Excel Formula - Bytes to Formatted Bytes
=LET(
README_,"This formula formats a byte count, rounding it to its significant digit and to two decimal places, applying the appropriate unit of measurement",
README1,"Adjust the below [variable] definitions to your need, where the viable options are (bracketed)",
README2,"[cell] specify the individual cell address containing the byte count to format, this should be contained within double quotation marks",
README3,"[cell_style] define if you're using the R1C1 (rowcolumn) or the A1 (alphanumeric) cell reference style",
README4,"[unit_type] define if you want the resulting output calculated to a base 2 (binary) or base 10 (metric) value",
CONSTANTS,"Do not alter these",
binary,1024,
metric,1000,
rowcolumn,0,
alphanumeric,1,
VARIABLES,"Adjust these to your need",
cell,"RC[-1]",
unit_type,binary,
cell_style,rowcolumn,
IF(N("Error if the speficied cell is not a number")+
NOT(ISNUMBER(INDIRECT(cell,cell_style))),"#MISSINGNO",
IF(unit_type=1000
+N("Calculate the result at base 10"),
IF((INDIRECT(cell,cell_style)>=1000^8),
TEXT((INDIRECT(cell,cell_style)/1000/1000/1000/1000/1000/1000/1000/1000),"#,## ????.00 \Y\B"),
IF((INDIRECT(cell,cell_style)>=1000^7),
TEXT((INDIRECT(cell,cell_style)/1000/1000/1000/1000/1000/1000/1000),"#,## ????.00 \Z\B"),
IF((INDIRECT(cell,cell_style)>=1000^6),
TEXT((INDIRECT(cell,cell_style)/1000/1000/1000/1000/1000/1000),"#,## ????.00 \E\B"),
IF((INDIRECT(cell,cell_style)>=1000^5),
TEXT((INDIRECT(cell,cell_style)/1000/1000/1000/1000/1000),"#,## ????.00 \P\B"),
IF((INDIRECT(cell,cell_style)>=1000^4),
TEXT((INDIRECT(cell,cell_style)/1000/1000/1000/1000),"#,## ????.00 \T\B"),
IF((INDIRECT(cell,cell_style)>=1000^3),
TEXT((INDIRECT(cell,cell_style)/1000/1000/1000),"#,## ????.00 \G\B"),
IF((INDIRECT(cell,cell_style)>=1000^2),
TEXT((INDIRECT(cell,cell_style)/1000/1000),"#,## ????.00 \M\B"),
IF((INDIRECT(cell,cell_style)>=1000^1),
TEXT((INDIRECT(cell,cell_style)/1000),"#,## ????.00 \K\B"),
IF(INDIRECT(cell,cell_style)=1,
"1 B",TEXT(INDIRECT(cell,cell_style),"## ????0 \B")
))))))))),
IF(unit_type=1024
+N("Calculate the result at base 2"),
IF((INDIRECT(cell,cell_style)>=POWER(2,80)),
TEXT((INDIRECT(cell,cell_style)/POWER(2,80)),"#,## ????.00 \Y\i\B"),
IF((INDIRECT(cell,cell_style)>=POWER(2,70)),
TEXT((INDIRECT(cell,cell_style)/POWER(2,70)),"#,## ????.00 \Z\i\B"),
IF((INDIRECT(cell,cell_style)>=POWER(2,60)),
TEXT((INDIRECT(cell,cell_style)/POWER(2,60)),"#,## ????.00 \E\i\B"),
IF((INDIRECT(cell,cell_style)>=POWER(2,50)),
TEXT((INDIRECT(cell,cell_style)/POWER(2,50)),"#,## ????.00 \P\i\B"),
IF((INDIRECT(cell,cell_style)>=POWER(2,40)),
TEXT((INDIRECT(cell,cell_style)/POWER(2,40)),"#,## ????.00 \T\i\B"),
IF((INDIRECT(cell,cell_style)>=POWER(2,30)),
TEXT((INDIRECT(cell,cell_style)/POWER(2,30)),"#,## ????.00 \G\i\B"),
IF((INDIRECT(cell,cell_style)>=POWER(2,20)),
TEXT((INDIRECT(cell,cell_style)/POWER(2,20)),"#,## ????.00 \M\i\B"),
IF((INDIRECT(cell,cell_style)>=1024),
TEXT((INDIRECT(cell,cell_style)/1024),"#,## ????.00 \K\i\B"),
IF(INDIRECT(cell,cell_style)=1,
"1 B",TEXT(INDIRECT(cell,cell_style),"## ????0 \B")
)))))))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment