Ads 468x60px

Tuesday, July 3, 2012

Custom Number Formats (Multiply & Divide by any Power of 10)

Custom Number Formats (Multiply & Divide by any Power of 10):
In the past here at Chandoo.org and at many many other sites, people have asked the question “How can I display a number Multiplied or Divided by 10, 100, 1000, 1000000 etc, but still have the cell maintain the original number for use in subsequent calculations“.
Typically the answer has been limited to “It can’t be done” or “It can only be done in multiples of 1000”.
Well thanks to a tip I picked up from Kyle who responded to a post here at Chandoo.org they are all wrong.
It is possible to Multiply or Divide any cell contents by any power of 10 using Custom Number Formats !
That is:

How does this work:

When using custom number format we have two possibilities to modify the display number
  1. Use a Comma to divide by 1000; or
  2. Use a % to Multiply by 100
So using a combination of these any power of 10 can be obtained.

So using the correct combination of , and % can result in any power of 10 multiplier we require.
The problem is that using a % adds a % to the number!
The trick which Kyle added is that adding a Ctrl J to the Custom Number format allows us to hide the % signs on a second row of text, then by adjusting the cell to have word wrap and adjusting the row height the second row is not visible.
The Ctrl J must be added after the ,’s and before the %’s
So using the examples above the table is:

The Ctrl J adds a Carriage Return, chr(10), to the Format String.
Finally after applying the Custom Number Format the Cell must be edited to enable Word Wrap.
Select the Cells with the custom Formats, Ctrl 1, Alignment


You can see the hidden % symbols if you increase the Row Height.


Combination with Regular Custom Formats

These Custom Number Formats can of course still be combined with regular Custom Number Formats, just make sure that the Ctrl J is inserted before the % signs:

No Loss of the Cells Value

It is also worth noting that the original number is still maintained internally in the cell and that cells dependent on the cells don’t have to adjust for the display value.


Multi Line Formats

By extension we can now use this technique to add multiple Lines of Text to a Custom Number Format


Downloads

You can download a file containing all the above example here: Download Here

Other Links to Custom Number Formats

Here:

http://chandoo.org/wp/2008/02/25/custom-cell-formatting-in-excel-few-tips-tricks/
http://chandoo.org/wp/2011/11/02/a-technique-to-quickly-develop-custom-number-formats/
http://chandoo.org/wp/2011/08/19/selective-chart-axis-formating/
http://chandoo.org/wp/2011/08/22/custom-chart-axis-formating-part-2/
http://chandoo.org/wp/tag/custom-cell-formatting/

Elsewhere

http://www.ozgrid.com/Excel/CustomFormats.htm
http://peltiertech.com/Excel/NumberFormats.html

Thanx

Just a quick final Thank You to Kyle for highlighting this Custom Number Format feature/trick last week
I look forward to your comments below:



0 comments:

Post a Comment