Concatenante and include leading zeroes - excel

So currently I am pulling numbers from a spreadsheet that automatically formats their numbers into a certain amount of digits using special number formatting, so that it outputs with leading zeroes.
Example:
(zipcode formatting) 6 digits -
12345 becomes 012345
(Chinese (PRC) formatting) 6 digits -
12 becomes 000012
(Chinese (Taiwan) formatting) 3 digits -
0 becomes 000
My concatenate would put them together with periods between them; however, it does the base numbers instead of the formatting it should be doing.
=CONCATENATE(A1,".",B1,".",C1)
012345 000012 000 becomes 12345.12.0 instead of 012345.000012.000
Is there a function or something that will work to make it pull the converted special number instead of the one typed? It should ALWAYS be 6 digits.6 digits.3 digits.

Try this:
= TEXT(12345,"######000000") & "." & TEXT(12,"######000000") & "." & TEXT(0,"###000")

Related

Extract 9 last number from a number of 14 digit

One of my Excel column of my board have to store numbers of 9 digits.
I'm looking for a solution to keep only the 9 last digits of any bigger number past in this specific column. It's only entire number.
Also if after formatting the number it appear that the number starts with 0 the 0 have to be kept. Is there another solution than adding an '0 at first ?
Here is what I already done : (i is the row number / Range01 is Range("A14:O400"))
If Len(Range01.Cells(i,5).value) = 9 Then
Range01.Cells(i,5).Interior.color = vbGreen
ElseIf Len(Range01.Cells(i,5).value) = 8 Then
Range01.Cells(i,5).value = "'0" & Range01.Cells(i,5).value
ElseIf Len(Range01.Cells(i,5).value) > 9 Then
????
Else
Range01.Cells(i,5).Interior.color = vbRed
End If
Thanks for the help.
The simplest way to get the last nine numbers of an integer is:
=MOD(A1,1000000000)
(For your information, that's one billion, a one with nine zeroes.)
If you're interested in showing a number with leading zeroes, you can alter the cell formatting as follows: (the format simply contains nine zeroes)
If you're interested in keeping the zeroes, you might need to use your number as a string, and precede it with a good number of repeated zeroes, something like:
=REPT("0",9-LEN(F8))&F8
Take the length of your number (which gets automatically converted into a string)
Subtract that from 9 (so you know how many zeroes you need)
Create a string, consisting of that number of zeroes
Add your number behind it, using basic concatenation.
You can simply use the math operator of modulus. If you want the last 9 digit you can write:
n % 10000000000
Where n is the number in the column.
In VBA:
MOD(n,1000000000)

Need excel formula to extract a single or double digit number preceding a character or symbol

Here's the case I have a column with a number of text strings. Each string contains either a single or double-digit number followed by either an "x" or the words " set" or " rounds." I'm trying to extract the numbers preceding the "x" or the words. Here's an example:
string
Desired Outcome
jump 3x10
3
push 10x3
10
pull 3 sets 10 times
3
pull 3 rounds 8 times
3
push 10 times 3 sets
3
I've tried FIND, SEARCH, {1,2,3,4, 5, 6,7, 8, 9} only to over-complicate this. There has to be a simple way to locate these combinations (##&"x", "## sets" or ""## rounds") and extract the related numbers.
Assume "String" data housed in Column A1:A6 with header.
In "Outcome" B2, formula copied down :
=LOOKUP(9^9,0+RIGHT(LEFT(A2,MIN(SEARCH({"x"," sets"," rounds"},A2&"x sets rounds"))-1),ROW(A$1:A$250)))

convert 16 bit decimal into two 8 bit decimal in excel

I am finding a formula which can convert a 16 bit binary number into two separate decimal number
0000000110010000 -> 0x0190
I want the decimal number to be 1 and 144
I have 50 columns(say M1 to M50) of binary numbers so need to make a generic formula for this
If M1 contains your binary number (as a text string), then use
=BIN2DEC(LEFT(M1, 8))
to extract the left part
and
=BIN2DEC(RIGHT(M1, 8))
to extract the right part.
If you want the result in the same cell then use something like
=BIN2DEC(LEFT(M1, 8)) & "|" & BIN2DEC(RIGHT(M1, 8))
where the | is an arbitrary separator, which you can change or omit to suit personal taste.
are they all exactly 16 characters long? You could do:
=BIN2DEC(RIGHT(M1,8))
=BIN2DEC(LEFT(M1,8))

Trying to write power of (small numbers) with VBA code

I can't figure out how to write power of to cells in Excel. I can use chr(185),chr(178) and chr(179) to display the power of 1,2 and 3 but I can't do any other number.
You have 2 choices:
using unicode characters
using cell formatting
I think the formatting method is to be preferred for normal use because it is pretty flexible (e.g. easy to superscript a whole algebraic expression like x^(n-1)).
However, if you are ultimately exporting to a CSV or some other format then Excel formatting will not carry over, in which case you should use method 1. In addition, using this method allows the superscript characters to be passed around in formulae, compared to actual cell formatting that cannot be.
Using Unicode characters
Use the ChrW(charcode) function.
charcode can be the decimal or hexadecimal number for the unicode character.
The characters are:
SuperscriptHex Dec
0 2070 8304
1 00B9 185
2 00B2 178
3 00B3 179
4 2074 8308
5 2075 8309
6 2076 8310
7 2077 8311
8 2078 8312
9 2079 8313
(reference to unicode table: http://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts)
You can use &H as a literal indicating the chars that follow should be interpreted as hexadecimal, like ChrW(&H2077).
Using cell formatting
A Range object has a Characters property that returns a Characters object that allows different Font objects to different parts of the string. Normally, Range.Font is applied to the whole text.
Note that Font also has lots of other properties you can apply against the substring, like bold/size etc.
Examples:
'Method 1 - Unicode
ActiveCell.Value = "x" & ChrW(&H2079)
'Method 2 - Formatting
With ActiveCell.Offset(1, 0)
.Value = "x9"
.Characters(2, 1).Font.Superscript = True '2,1 is a substring from 2nd char for 1 char
End With

How to build complex value from three variables?

I have an Excel spreadsheet with over 2000 entries:
Field B1: CustomerID as 000012345
Field B2: CustomerID as 0000432
Field C1: CustomerCountry as DE
Field C2: CustomerCountry as IT
I need to build codes 13 digits long including "CustomerCountry" + "CustomerID" without leading 0 + random number (can be 6 digits, more or less, depends in length of CustomerID).
The results should be like this: D1 Code as DE12345967895 or D2 Code as IT43274837401
How to do it with Excel functions?
UPDATED:
I tried this one. My big problem is to say that random number should be long enough to get 13 characters in all. Sometimes CustomerID is just 3 or 4 digits long, and concatenation of three variables can be just 10 or 9 characters. But codes have to be always 13 characters long.
Use & to concatenate strings.
Use VALUE(CustomerID) to trim the leading zeroes from the ID
Use RAND() to add a random number between 0 and 1 or RANDBETWEEN(x,y) to create one between x and y.
Combine the above and there you are!
If you always want 13 digits you can use LEFT(INT(RAND()*10^13);(13-LEN(CustomerCountry)-LEN(VALUE(CustomerID)))) for the random number to ALWAYS be the right length.
total formula
= CustomerCountry
& VALUE(CustomerID)
& LEFT(INT(RAND()*10^13);(13-LEN(CustomerCountry)-LEN(VALUE(CustomerID))))
=C1 & TEXT(B1,"0") & RIGHT(TEXT(RANDBETWEEN(0,99999999999),"00000000000"),11 - LEN(TEXT(B1,"0")))
that should do it
I don’t understand what is where and OP has accepted answer so have not bothered testing:
=LEFT(RIGHT(C1,2)&VALUE(MID(B1,15,13))&RANDBETWEEN(10^9,10^10),13)
(but I might revert to this if no one else picks the flaws in it first!)

Resources