Formatting as Facade


October 09, 2017 - by

Formatting as Facade

This article reveals hidden secrets about Excel number formatting. How you can store numbers in Excel but add words next to the numbers. Read on for more cool tips about number formatting.

Excel is amazing at storing one number and presenting another number. Choose any cell and select Currency format. Excel adds a dollar sign and a comma and presents the number rounded to two decimal places. In the figure below, cell D2 actually contains 6.42452514. Thankfully, the built-in custom number format presents the results in an easy-to-read format.

Currency Format
Currency Format

The custom number format code in D2 is $#,##0.00. In this code, 0s are required digits. Any #s are optional digits.

However, formatting codes can be far more complex. The code above has one format. That format is applied to every value in the cell. If you provide a code with two formats, the first format is for non-negative numbers, and the second format is for negative numbers. You separate the formats with semi-colons. If you provide a code with three formats, the first is for positive, then negative, then zero. If you provide a code with four formats, they are used for positive, negative, zero, and text.

Positive, Negative, Zero and Text Formats
Positive, Negative, Zero and Text Formats


Even if you are using a built-in format, you can go to Format Cells, Number, Custom and see the code used to generate that format. Here is the code for the Accounting format:

Number Format Types
Number Format Types

To build your own custom format, go to Format Cells, Number, Custom and enter the code in the Type box. Check out the example in the Sample box to make sure everything looks correct.

In the following example, three zones are used. Text in quotes is added to the number format to customize the message.

Text in Number Format to Customize Message
Text in Number Format to Customize Message

If you create a zone for zero but put nothing there, you will hide all zero values. The following code uses color codes for positive and negative. The code ends in a semi-colon, creating a zone for zero values. But since the zone is empty, zero values are not shown.

Hide Zero with Number Formatting
Hide Zero with Number Formatting
Walter Moore
by Walter Moore
Custom Format
Custom Format

You can extend this by making all zones blank. A custom format code ;;; will hide values in the display and printout. However, you'll still be able to see the values in the formula bar. If you hide values by making the font white, the ;;; will stay hidden even if people change the fill color. The following figure includes some interesting formatting tricks.

Hide the Values in Display and Printout
Hide the Values in Display and Printout

In B2 and B3, if you put ** before the number code, it will fill to the left of the number with asterisks like the old check writer machines would do. But there is nothing that says you have to use asterisks. Whatever you put after the first asterisk is repeated to fill the space. Row 3 uses *! to repeat exclamation points.

In B4 and B5, each comma that you put after the final zero will divide the number by 1,000. The code 0,K shows numbers in thousands, with a K afterward. If you want to show millions, use two commas. The “M” code must be put in quotes, since M already means months.

In B6 put a stern message in the fourth zone to alert anyone entering data that you want a number in the cell. If they accidentally enter text, the message appears.

In B7 to B9 the normal zones Positives, Negatives, and Zero are overwritten by conditions that you put in square brackets. Numbers under 70 are red. Numbers over 90 are blue. Everything else is black.

In B10, those odd _( symbols in the accounting format are telling Excel to leave as much space as a left parenthesis would take. It turns out that an underscore followed by any character will leave as much white space as that character. In B10, the code contains 4 zeroes. But there are different amounts of space between each. The space between the 1 and 2 is the width of 2 WW characters. The space between 2 and 3 is the width of an N. The space between 3 and 4 is the width of a lowercase letter i.

The following figure shows various date formatting codes.

Various Date Formatting Codes
Various Date Formatting Codes

Note that the mmmmm format in row 8 is useful for producing J F M A M J J A S O N D chart labels.

Thanks to Dave Baylis, Brad Edgar, Mike Girvin, and @best_excel for suggesting this feature.

Watch Video

  • Number formatting is a façade: Excel stores one thing, shows us another.
  • For example: use decrease decimals to show a rounded version of the number.
  • Excel still stores all of the decimals, but simplifies the display.
  • There are 11 number formats in the drop-down on the home tab.
  • Click the dialog launcher to get to Format Cells dialog.
  • Today, we are talking about the formatting codes in the Custom group.
  • I don't have all the knowledge here today, so if you have better tips, put them in the YouTube comments.
  • A zero in the format code says Excel must display the digit.
  • A # sign says they may display the digit if there is enough precision, but they don't have to when there is not.
  • A ? will leave space for the digit to keep the decimal place lined up.
  • There can be 1, 2, 3, or 4 formats, separated by a semi-colon.
  • When there are 2 formats, the first is for zero and up. The second is for negative.
  • When there are 3 formats, the third if for zero.
  • 4th format is for text.
  • Using the number format to display text with number or to display text instead of number.
  • Specifying a color for a zone.
  • To change [Color 5] visit Excel options.
  • *x to repeat x up to the numbers
  • , at end to divide by 1000
  • ,, divides by millions
  • Using conditions in the zone
  • _x will leave space the size of "x"
  • m mm mmm mmmm mmmmm
  • d dd ddd dddd
  • [h]:mm
  • Thanks to Dave Baylis, Brad Edgar, Mike Girvin, and @best_excel for suggesting this feature.

Video Transcript

Learn Excel from MrExcel podcast, episode 2044 - Formatting as Façade!

Alright, I am podcasting all of my tips in this book, click the “i” on the top-right hand corner to get to the playlist!

We're talking about custom number formatting today, so I have Quantity, Revenue, and we are displaying a whole bunch of decimals here. And, you know, if we don't want to play all those decimals, and we don't want to use the ROUND function, I just come up here and using Decrease Decimal. it doesn't change the number that's actually stored behind the scenes, it's just displaying the way that Excel shows us the number. Alright, and so I'm stealing Mike Girvin’s term, that we're using formatting as a façade, right, there's a whole bunch of decimal stored in that cell, but we're using custom number formats to display that. And I want to go beyond the 11 formats here, and even click that dialog launcher, beyond most of the things that are here, and I want to talk about Custom. Custom number formats give us the world, alright?

And so here's a whole bunch of custom number formats that you can type in this box, and the results are shown to the left. So just General, you get all the decimal places, but here, zeroes before the decimal place are forcing zeroes to appear. So if the number < 100, I'm going to get a leading 0, sometimes that's useful for part numbers, zeroes after the decimal places force the numbers to appear. The hashtag or the pound sign (#) before the decimal place is optional, alright, so it can be there, it doesn't have to be there. Alright, so in this case we have the number 6, but because we have five zeroes, it's giving us leading zeroes. Now, if you need to VLOOKUP into a section of text that has 00006, this won't be a match, but if you just needed to look right, it'll work. OK, so some interesting things here, we use pound signs or hashtags a lot, “hashsigns” a lot. In the US we call this a pound sign, and I understand in England that's not a pound sign, £ is your currency that you call it a hash. Alright so, sorry, I've been calling it a pound sign my whole life, and it's hard for me to start calling a hash, but I'll work on that.

Alright, so down here the .000 says you're going to display the zeroes whether there's precision or not, and I've changed these numbers to be 6.42 and 6.4. Now this is interesting, this is one I never really knew, if you put a ? instead of the 0, it says that it'll display the precision if it's there, but if not, don't display it, but don't let things flow to the right. Alright so here, let's change these numbers, 6.42 and 6.4, alright, see here, the decimals don't stay lined up. If you want the decimals to stay lined up, use the question marks, if you want to force the zeroes to be there, use the zeroes.

Now hey, as we go through here, there is a LOT of detail in minutia, but I do not have the corner on the knowledge here. If you see me miss some cool number formatting trick, please leave that down in the in the YouTube comments. Alright now, here's the next concept, we can display 1, 2, 3, or 4 number formats in the Type box, if you display just 1, it's just the number that's used for everything, alright. But if you display 2 and they're separated by a semicolon, then the 1st one’s for numbers >=0, and the 2nd one’s for numbers <0. So right here I've used two codes, +0;-0, and so that means the negative numbers show up with a minus, but the positive numbers show up with the plus, but because I didn't specify what happens for 0, it shows up with a plus as well.

So we can add a 3rd zone: positive, negative, zero, alright, so +0;-0;0 , alright, so that handles zeroes. There can even be a 4th code of what to do if someone enters text. Alright now, next concept, in the custom number format, in addition to the zeroes, you can put text in quotes! Alright, so let's take a look at the custom number format here, for positive numbers, the words “Please Remit “ and then the number, for negative “Credit Balance of “ the number and “(Do Not Pay)”. And for 0, I don't even show the number, I just show “No Balance”, alright. So you can actually use this to replace the number, this is -1, 0, and 1, and these are formulas, to get the formula is just to copy that down. All negative numbers will say “Loser!” or “Down” or the word “Minus ” and the number, so we put in -5, still says “Loser!” or “Down” or “Minus 5”. For 0, we can have it say “Zero” or say “Flat” or say “0”, and then for a positive number, let's put it in 55, “Winner!”, “Up”, or “Positive 55”, alright, so you can actually add words. And what's cool, so this is 55, 55, 55, if I would SUM that, they're really numbers, and it's really going to work, like normally the SUM wouldn't work with text, but that actually gives me an answer. And so, if you want to keep numbers there, but display words in the cells, this is a great trick.

Alright now, these are the characters can be used in the custom number format without quotes, so if you happen to just need a + or a -, that's why you don't have to put it in quotes. And there's some additions to this, like once I saw this list, I'm like “OK, let's see what we can screw around with.” All of these are the numbers 1 2 3 4, so if I used a custom number format of {(number>&, all of that will display. If I want to separate the digits by dashes, this is a custom number format to get that to work. And these are all real, so 7854, see everything changes, these are all formulas coming down here. So I can kind of screw with the custom number format, and put characters before it, put characters after it. One that's not in the list that I know it works is K, you're allowed to put a K at the end, and it's not in quotes. But M, because M means months or minutes, you'd have to put it in quotes or put this \M to get an M to appear at the end.

Alright, next concept, in each zone you're allowed to specify color, right, so up here the positive numbers are green, and the negative numbers are blue. Ctrl+1 to get to Format Cells, before the custom number format, in the first zone, the positive zone, I said green, and for negative numbers I said blue. What color are we allowed to use there? Goes back to the days of 8 colors, so black, green, white, blue, magenta, yellow, cyan, and red. But thanks to Mike Alexander, you're allowed to use 56 other colors, Color 1, Color 2, has to be in [], like that, those are the 56 colors. If you need to change these, we're getting really deep now, now we're going into Charlie kid territory! Excel Options, Save, and then click Colors, alright, and like, if I wanted to change that orange to something else, maybe the purple, click OK, click OK, click OK, and one of these, I can't tell which one it is would have changed to that color. Another cool trick, what if you want to hide all numbers? So you have some secrets here, and you don't want anyone to see them. Ctrl+1, put a custom number format, I'm saying “Display nothing for positive, nothing for negative, nothing for 0” click OK, and everything's hidden. Of course, they can still see it up here in the formula bar, so it's not perfect, alright, here's some other customer formatting characters.

An asterisk says “Display the next character like a check-writer”. So those ** is saying “You know, fill the area up until the number with asterisks”, but you can change that, you can make that character anything you want! So *! will put all exclamation points in there, let's change this, Ctrl+1, will change it to *X, and I will get all X's up until that point. So you can create the check-writer effect, but it doesn't have to be with an asterisk, you can put whatever you want in there. Put a comma at the end, so this is 123456, custom number format with a comma after the zero says “Display this in thousands, divided by 1000”, I put the ,K there for thousands. When you want to do it in millions, so there's our 0.0,, each comma says “Display, but divide it by another 1000”. So that's dividing by a million, put the “M” to display millions. I know some people use MM there, my sister Alice(?) who works for Procter & Gamble, “MM” has to be in quotes.

Now here, this is one where we're forcing a number, if someone enters something is not a number, the message in the 4th zone is going to overwrite it. So if we put in the number 1, it’s great, put in -1, it’s great, if we put in “Hello”, he yells at us, “Enter a number!”. Alright, again, these are formulas that are pulling whatever I type into A over to B. You can use conditions, alright, so the positive, negative, zero, you can override that. So I'm going to say red if it's <70, blue if it's >90, and you can only have two conditions, and then a 3rd zone for things that are not <70 or >90, old, old-fashioned conditional formatting. Another one, here's another one, this is just crazy, is putting an underscore and then any character leaves enough space to fit that character. You see this a lot with _( to keep the positive numbers lined up with the negative numbers, but you can really screw with Excel. So W is the widest character, so this is putting the 1st digit, and then enough space for 2 W's, and then the 2nd digit and enough space for an N, and then the 3rd digit and enough space for an I, and then finally, the 4th digit. Is this useful for anything? Gee, I don't know, but it's kind of wild, that you can force different spacing between the digits by using the underscores.

Alright, dates, m/d/yy, you get a 2-digit year, expand to yyyy, you get a 4-digit year, put mm, it forces a leading 0 before the 7, dd forces a leading 0 before the 3. If you want to use some old-fashioned cobalt date format, don't put any /, just all the characters, YYYYMMDD. mmm spells out the month abbreviation, mmmm spells out the entire month, mmmmm gives you the JASON format. Why do I call it the JASON format? If you look at the Wall Street Journal, their financial shorts always have JFMAMJJASOND. Back in 1984, I want a vinyl copy of “Frankie & the Knockouts - Below the Belt” for answering the trivia question “What man's name can be spelled by using the month abbreviations?” And because I was reading The Wall Street Journal in school, I knew that Jason was the name, and I won that. I probably gave it away at a garage sale for $50c, my bad. Alright, dd gives you the leading digit before the date, ddd spells out the abbreviation, dddd gives you the entire day name, weekday name, ddddd doesn't do anything. You can combine these however you'd like. dddd spells out the day, Tuesday, put the word “ the ” in quotes, the day itself of mmm, gives you the abbreviation, alright, so you can combine these however you’d like.

Time, one weird thing with time so, h:mm, or AM/PM, so if you don't put the AM/PM it forces into 24-hour time, if you do, then you get 2:15 PM. If you have hh, it forces the leading zero before the 2, you can even add .0 after the seconds to get milliseconds. Now here's the bizarre thing, actually before I get to the bizarre thing, I don’t know, let's do the bizarre thing first. Let's do =SUM of all of those, so all of those are 14 hours, 6*14=84, it should be 84 hours, but if I format it as a time, it's saying 1:30 in the afternoon, alright, and here's the thing. So we have a number here, this morning 10/9/2016 at 6 AM, and I just have formulas copying that down, and I can override, remember, it's formatting as a façade. I can say “Hey, just show me the years, just show me the month, just show me the days, just show me the time portion of that.” And over here in this SUM, when we're asking for a time, we're saying “Hey, ignore the years, the months, the days, just show me the time.” and what this really is, this is three days + 1:30 in the afternoon.

So in order to get this to display correctly, you either come into Time and look for the one that says 37 hours, or go to Custom, and you'll, see putting the [h] says “Show us the full number of hours.” So if I need to see hours and minutes, [h]:mm will show me that, that is actually 85.5 hours, I see, I was writing off the 15 minutes, trying to get the 84 in my head, I was close. Where else can you use square brackets? So 6 AM, you can show the hours, you can show just the minutes, 6 AM is 360 minutes, or just the seconds using the square brackets. Alright so, let's go back to one of the number formats we have under the Accounting format, and see if now, after this really long episode, we understand what's going on.

So what this is saying, _( says “Leave as much space as a ( in the positive value.” “* “ says “Repeat spaces until you get to the numbers.” The #,##0 says “We're going to use the comma separator, don't put leading characters if we don't have the precision, always put two decimal places.” And then _) says “Leave as much space as ), and that's for the positive numbers.” OK now, for the negative numbers, it's really bizarre out here, before the $ they're leaving as much space as a ( so in other words, they're never going to display that. Again “* “, but here they're now going to put in the ( and the ). And then for 0, leave as much space as the ( and as much space as the ). Don't put anything, we're replacing the zero with the “-“, but then leave as much space as two decimal places, so that way that it's going to line up with this. And then finally in the 4th zone, if they type in text, leave enough space for ( and a ), and then put the text in.

Alright, this was always just a lot of nonsense than me, but there's specific meanings for all of those characters. It's crazy that all of this information, 18 minutes worth of podcast, comes from 3 pages in this book, just imagine how much is there in all 200 pages of the book. Buy the book, click the “i” on the top-right hand corner, you'll appreciate it, and I'll appreciate it. Alright, long, long episode: Number formatting is a façade, Excel stores one thing, it shows us another. Decrease Decimal and Increase Decimal is a great example of that, they still store all the decimals, but it simplifies the display. There's 11 formats here, but really to get to them, you go to the dialog launcher, and then you can choose, something and then modify it in Custom if you want to. Talked about all this custom number formatting codes, if you have better tips, please put them in the YouTube comments.

Zero in the format code says “Excel MUST display the digit, whether there's precision or not.” Hash sign, pound sign says they may display the digit if there's a precision, but they don't have to. Question mark says “Leave the space for the digit if there's not enough precision.” There can be up to 4 formats separated by a semicolon, that way we have a different number for positive, negative, zero, and text. 2 formats, the 1st one is for non-negative, the 2nd one is for negative, if you had a 3rd format, the third format is for 0, the 4th format is for text, if it's there. Alright, we can display text with a number, or display text instead of the number, “Winner”, “Loser”, or “Up”, “Flat”, “Down”. You can specify a color for each zone, to change the color codes visit Excel Options, Save, Colors. Asterisk any character to repeat that character before the numbers, like a check-writer would do. Put comma at the end to divide by a thousand, two commas to divide by millions, 3 commas divides by billions, and so on. We can use conditions in the zone, and then underscore X will leave a space the size of X. Alright, the different variations of months, whether you put one digit, two digits, the abbreviation, spell it out, or just the first initial. Days, one digit, two digits, abbreviate, or spell it out, there is no 5th. And then finally, to get times in excess of 24 hours, you have to put that h in square brackets, and other variations of that.

Thanks for hanging out to the end! We'll see you next time for another netcast from MrExcel!

Download File

Download the sample file here: Podcast2044.xlsm

Title Photo: PixelAnarchy / Pixabay