Format numbers as billions / millions / thousands, smartly [duplicate] - excel

This question already has answers here:
ultimate short custom number formatting - K, M, B, T, etc., Q, D, Googol
(3 answers)
Closed 1 year ago.
Any recipes out there for a "smart" number formatting formula that's "scale-aware," a la Rails ActionView's distance_of_time_in_words method?
I would expect to enter a number like: 1,816,724 and see 1.8M (or enter 2,394 and see 2.4K).

To format conditionally using Billions / Millions / Thousands in Google Spreadsheets or Excel, you can use:
[<999950]0.0,"K";[<999950000]0.0,,"M";0.0,,,"B"
To apply this setting in Google sheets, goto Format > Number > Custom Number Format and copy paste the above format string.
To learn more about formatting options, go to https://support.google.com/docs/answer/56470#zippy=%2Ccustom-number-formatting

Select the cells to receive a custom number format and tap Ctrl+1. When the Format Cells dialog opens, go to the Number tab and choose Custom from the list down the left side. Supply the following for the Type:,
[>999999]0.0,,\M;[>999]0.0,K;0
Note that M is a reserved character in a format mask and must be escaped with a backslash to become literal. You can also wrap it in quotes but since I use custom number formats in VBA's .NumberFormat property, I prefer the escape character to avoid having to deal with quotes within quoted strings. Your results should resemble the following:
        

You can simply try this one:
=IF(A1<1000,A1,IF(A1<1000000,ROUND(A1/1000,1)&"K",ROUND(A1/1000000,1)&"M"))
supposing that your number is in A1.

Related

Custom Format/Modify Cells Column Excel

I am trying to custom format/modify a number in excel and want to restrict the decimal to allow only ones and tens digits THEN a decimal followed by the remainder of the number. For example, the number 32248558 should be displayed as 32.248558, and the next number in sequence would go from 32186449 to 32.186449.
This would need to be done for the entire column of data.
Assuming the data is starting in A1, use TEXT() to format data. TEXT() can format using predefined settings (ex: "general") or heavily customized (ex: "MMM/DD/YYYY H:m:s"). More info can be found here: https://www.ablebits.com/office-addins-blog/2017/01/11/excel-text-function-formula-examples/
=TEXT(A1/1000000,"0.000000")
then drag this to the end of your dataset.

Determine the number of search results upon using different sets of separators (Excel)

I would like to ask for your help with the formulation of a formula in Excel in order to compare the total number of search results upon using different sets of separator characters.
As I have multiple columns with content, as in the example below, I thought it would be possible to Count the search results in some way and do this for each column separately ( I would actually prefer to treat each column separately).
A
1 L-516-S-221-S-223
2 H-140.STR3
3 ST0 XP 23-9
4 etc.......
Preferably, I would like to use a varying a set of separator characters in order to determine the impact on the number of search results based on this set of separator characters. Logically, with an increasing number of separators more results will be returned (depending on separators included in the cell values of course).
The set of characters that I would like to experiment with is: “-_ .,;: “
Hopefully this makes sense and someone is able to help me out. Thank you.
Kind regards,
P
In your example - on its own will detect all three instances but for an overview you might construct a grid (say B1:H1 of your separators, including a space rather than an empty cell) and ColumnA each column in turn (maybe via links) then a formula in B2 such as:
=--ISNUMBER(FIND(B$1,$A2))
copied across to ColumnH and down to suit.
Alternative formula (for different question):
=IF(LEN($A2)-LEN(SUBSTITUTE($A2,B$1,""))>0,LEN($A2)-LEN(SUBSTITUTE($A2,B$1,""))+1,0)
Assumes, for example, no trailing spaces and separators are always separated. Results are not necessarily cumulative.

Concatenate Custom Function

On a daily basis I need to load data to one of our systems. However Excel deletes the previous zeros in front of the contractor IDs. So i have to add THREE zeros manually. I normally use the CONCATENATE function however now the IDs are coming differently so some IDs now only need to have TWO zeros added.
example:
ID
911111
I use concatenate to make it look like:
000911111
I came up with the IF formula that detects if the ID starts with a number NINE, to concatenate TWO zeros and if not, then to add THREE zeros.
example:
=IF(LEFT(A32,1)="9",CONCATENATE("00",A32),CONCATENATE("000",A32))
Now I want to create this formula as a custom defined so I do not have to write down the formula ever time I work on the data every day.
Any suggestions I will really appreciate.
In addition to the formatting responses provided in the comments, you could use the RIGHT function to cut off the leading zeroes to the appropriate amount.
For example, assuming A1 holds a string of numbers, between 0 & 9 digits long. We can create text representing a 9 digit string, with as many leading zeroes as necessary, as follows:
=RIGHT(REPT("0",9) & A1,9)
REPT("0",9) tells Excel to repeat the character "0" 9 times. It then tacks on whatever text is in A1. Then it takes only the rightmost 9 characters of the concatenation.
I generally would recommend the Formatting options noted in those comments, unless you need the text to be 9 characters for other formula purposes.

Why do Excel values in parentheses become negative values?

A colleague and I encountered a behavior in Excel which isn't clear to us.
Background:
We have a tool which converts an Excel sheet into a table format. The tool calculates the formulas which are in excel and replaces variables inside it with specific values.
The excel tool is used by one of our customers who use values like (8) or (247).
These Value are automatically translated by excel to -8 or -247.
Question:
I saw that many people want to display negative numbers in parentheses. But why would Excel change values in parentheses to a negative number?
I know that I could simply change the cell config to text and this would solve the problem but I wonder if there is a reason for the behavior, since there seems to be no mathematical reason for this.
Its simply the different format of cells you are bringing the "values from" and "pasting to". ..... numbers with parentheses are in cells with "accounting" format and negatives are stored in general or standard number formated cells. To resolve you can change the format of destination cells to accounting using cell formatting as number>accounting.
To answer the why, it's because accountants put negative numbers in brackets for readability
Unfortunately, this is one of the excel feature/bugs that helps some folks and frustrates others. When opening a file or pasting content, excel will immediately and always try to parse any values into formats it deems appropriate, which can mess up data like:
Zip Codes / Tel. # → Numeric: 05401 → 5401
Fractions → Dates: 11/20 → Nov, 20th YYYY
Std. Errors → Negative Numbers: (0.1) → -0.1
For some workarounds , see Stop Excel from automatically converting certain text values to dates
Once the file is open/pasted, the damage is already done. At that point, your best bet is:
Updating the field and displaying as text (appending with ') to prevent re-casting
Formatting the field if the operation wasn't lossy and is just presenting the info differently
Running a clean if/else to pad or other convert your data based on the identified errors
Specific to displaying values back in parens, if excel is converting them and treating them like negative numbers (which may or may not be the appropriate way to actually store the data), you can apply a different format to positive and negative numbers to wrap back in parens.
It is standard practice to write negative values as numbers in parentheses, especially in accounting. This makes negative values stand out much more than a simple negative hyphen; compare -1 and (1).
Excel is a tool very commonly used by accountants and supports accountant-style spreadsheets. Therefore, entering (100) means having a value of -100, even if there is no minus hyphen!
Here is a fun fact, if you enter (-10), Excel will treat it as normal text.

Add leading zeroes/0's to existing Excel values to certain length

There are many, many questions and quality answers on SO regarding how to prevent leading zeroes from getting stripped when importing to or exporting from Excel. However, I already have a spreadsheet that has values in it that were truncated as numbers when, in fact, they should have been handled as strings. I need to clean up the data and add the leading zeros back in.
There is a field that should be four characters with lead zeros padding out the string to four characters. However:
"23" should be "0023",
"245" should be "0245", and
"3829" should remain "3829"
Question: Is there an Excel formula to pad these 0's back onto these values so that they are all four characters?
Note: this is similar to the age old Zip Code problem where New England-area zip codes get their leading zero dropped and you have to add them back in.
=TEXT(A1,"0000")
However the TEXT function is able to do other fancy stuff like date formating, aswell.
The more efficient (less obtrusive) way of doing this is through custom formatting.
Highlight the column/array you want to style.
Click ctrl + 1 or Format -> Format Cells.
In the Number tab, choose Custom.
Set the Custom formatting to 000#. (zero zero zero #)
Note that this does not actually change the value of the cell. It only displays the leading zeroes in the worksheet.
I hit this page trying to pad hexadecimal values when I realized that DEC2HEX() provides that very feature for free.
You just need to add a second parameter. For example, tying to turn 12 into 0C
DEC2HEX(12,2) => 0C
DEC2HEX(12,4) => 000C
... and so on
I know this was answered a while ago but just chiming with a simple solution here that I am surprised wasn't mentioned.
=RIGHT("0000" & A1, 4)
Whenever I need to pad I use something like the above. Personally I find it the simplest solution and easier to read.
I am not sure if this is new in Excel 2013, but if you right-click on the column and say "Special" there is actually a pre-defined option for ZIP Code and ZIP Code + 4. Magic.
If you use custom formatting and need to concatenate those values elsewhere, you can copy them and Paste Special --> Values elsewhere in the sheet (or on a different sheet), then concatenate those values.
Even this will work nicely
REPT(0,2-LEN(F2)&F2
where 2 is total number of digits, for 0 ~ 9 -> it will display 00 to 09 rest nothing will be added.
Assuming that the number you want to pad is in cell A1, and the "padding number of zeros" is 4 ,
e.g.
"23" should be "0023",
"245" should be "0245", and
"3829" should remain "3829"
then
=TEXT(A1,REPT("0",4))

Resources