Convert bytes to KB or MB automatically

andreasvesalius

New Member
Joined
Sep 23, 2005
Messages
5
I have a column that contains data of file sizes in bytes. I wat to convert it automatically in Kilo or Mega bytes if the number is greater than 1024 or 1024 x 1024 respectively.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
=if(a1>1024*1024,a1/1024/1024&" MB",if(a1>1024,a1/1024&" KB",a1&" Bytes"))
 
Upvote 0
Thank you Barry and hatman. Excuse my ignorance, but as I'm completely new to modifying cells with formulas, how can I apply your examples to a whole column in my worksheet?
 
Upvote 0
Another possible way... custom formatting:

With "Bytes" as a tag..
[>=1048576]#,##0.0,,_k"MB";[>=1024]#0.0,_m"KB";#.0_m"Bytes"

Without "Bytes"
[>=1048576]#,##0.0,,_k"MB";[>=1024]#0.0,_m"KB";General


Copy the format you want to apply, highlight your range of interest, select format/cells/number tab/custom. Below the word "Type:" (white box) paste the format there then hit ok.
 
Upvote 0
Place the formula in a cell in the same row, to the right of the first cell with a file size and change the reference to refer to that cell. Then, just copy down as far as needed. In my example, I placed the formula in cell B2 and referred it to cell A2, and copied down.
 
Upvote 0
Thank you, Drew! Your example just worked fine! :biggrin:
Can any of you please explain how can I apply the formulas in the previous examples to a whole (B) column?
 
Upvote 0
Thank you, Barry! Without your clear explanations I would have never made it! I tried to insert your example in the formula bar and nothing happened. Now I can appreciate your examples.
Thank you all for your kind help!
 
Upvote 0
Here is my "modification", that imitates Windows file size report more closely:

=IF(B1>=1048576,ROUND(B1/1048576,2)&" MB",IF(B1>=1024,ROUND(B1/1024,2)&" KB",B1&" bytes"))
 
Upvote 0

Forum statistics

Threads
1,214,917
Messages
6,122,233
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top