|
|
How to format a number as B, KB, MB, or GB?
Square Peg posted on Sunday, January 11, 2009 11:32 PM
Is there a way to format the value in a cell so that
if it's it displays as
without changing the actual value in the cell? |
|
|
|
|
hi, !
Héctor Miguel posted on Monday, January 12, 2009 12:28 AM
hi, !
I left-out the first section (nnnB), for the other three I used this custom format:
[<1e6]0.0," Kb";[<1e9]0.0,," Mb";0.0,,," Gb"
change the order if you use more "B" than "Gb"
hth,
hector. |
|
Alternatively, use Engineering Notation - scientific notation with powers of
Bernard Liengme posted on Monday, January 12, 2009 7:50 AM
Alternatively, use Engineering Notation - scientific notation with powers of
3
http://people.stfx.ca/bliengme/ExcelTips/EngineeringNotation.htm
best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email |
|
How to format a number as B, KB, MB, or GB?
angelo posted on Monday, January 12, 2009 8:53 AM
Hi there,
well it is n
Square Peg a écrit : |
|
When you copied that entire text (verbatim, by the way) from when I originally
Rick Rothstein posted on Monday, January 12, 2009 2:36 PM
When you copied that entire text (verbatim, by the way) from when I
originally posted that solution on December 14, 2008 (subject line
sentence...
numbers and execute this code from the Immediate Window..."
doesn't mean much unless you include the last line I originally posted,
namely, this line...
Selection.Formula = Selection.Formula
--
Rick (MVP - Excel)
You can't do that with straight cell formatting, but you can implement
it
using event code. Right click the tab at the bottom of the worksheet
and
select View Code from the popup menu that appears, then copy/paste
the
following into the code window that opened up...
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C:C")) Is Nothing Then
If Target.Value < 1000 Then
Target.NumberFormat = "0 \B"
ElseIf Target.Value < 999500 Then
Target.NumberFormat = "0.000, \K\B"
ElseIf Target.Value < 999500000 Then
Target.NumberFormat = "0.000,, \M\B"
ElseIf Target.Value < 999500000000# Then
Target.NumberFormat = "0.000,,, \G\B"
Else
Target.NumberFormat = "0.000,,,, \T\B"
End If
End If
End Sub
Since you didn't tell us what cells, I assumed Column "C" (change the
Range
inside the Intersect function to the cell range you want to have this
functionality). After doing this, any numbers entered into those cells
will
adopt the number format you requested. Note that existing numbers will
not
change unless re-entered. You can do that one at a time or you can
select
all the existing numbers and execute this code from the Immediate
Window... |
|
How to format a number as B, KB, MB, or GB?
Square Peg posted on Monday, January 12, 2009 7:51 PM
Oooppps... Sorry. I forgot I already asked and was answered. I think I
got busy with the holidays and forgot to implement your solution. I will
give it a try now. |
|
How to format a number as B, KB, MB, or GB?
Ajay posted on Monday, January 12, 2009 11:36 PM
You can't do that with straight cell formatting, but you can implement
it
using event code. Right click the tab at the bottom of the worksheet
and
select View Code from the popup menu that appears, then copy/paste
the
following into the code window that opened up...
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C:C")) Is Nothing Then
If Target.Value < 1000 Then
Target.NumberFormat =3D "0 \B"
ElseIf Target.Value < 999500 Then
Target.NumberFormat =3D "0.000, \K\B"
ElseIf Target.Value < 999500000 Then
Target.NumberFormat =3D "0.000,, \M\B"
ElseIf Target.Value < 999500000000# Then
Target.NumberFormat =3D "0.000,,, \G\B"
Else
Target.NumberFormat =3D "0.000,,,, \T\B"
End If
End If
End Sub
Since you didn't tell us what cells, I assumed Column "C" (change the
Range
inside the Intersect function to the cell range you want to have this
functionality). After doing this, any numbers entered into those cells
will
adopt the number format you requested. Note that existing numbers will
not
change unless re-entered. You can do that one at a time or you can
select
all the existing numbers and execute this code from the Immediate
Window... |
|
The OP asked how to "format the value in a cell so that if it's it displays as.
Rick Rothstein posted on Thursday, January 15, 2009 2:17 PM
The OP asked how to "format the value in a cell so that if it's it displays
as...", not how to show it in that format in a different cell.
--
Rick (MVP - Excel)
Use this formula and your problem will be solved : =IF
(A2>999499999,TEXT((A2/999500000),"0.00")&" GB",IF(A2>999499,TEXT
((A2/999500),"00.00")&" MB",IF(A2>999,TEXT((A2/1000),"00.00")
&"KB",A2&" B"))) |
|
How to format a number as B, KB, MB, or GB?
Ajay posted on Friday, January 16, 2009 2:28 AM
l
ng
Use this formula and your problem will be solved : =3DIF
(A2>999499999,TEXT((A2/999500000),"0.00")&" GB",IF(A2>999499,TEXT
((A2/999500),"00.00")&" MB",IF(A2>999,TEXT((A2/1000),"00.00")
&"KB",A2&" B"))) |
|
|
|
|
Didn't Find The Answer You Were Looking For? |
| EggHeadCafe has experts online right now that may know the answer to your question. We pay them a bonus for answering as many questions as they can. So, why not help them and yourself by becoming a member (free) and ask them your question right now? |
| Create Account & Ask Question In Live Forum |
|
|
|
|
|
|
|
|