Need to add 0 to match the length - excel

I have unique identifiers for each row. For example 19Jan187938 or 19Jan206414 but there are some which are like 19Jan17333. I need to add a 0 before the number if it's 5 digits, so it becomes 19Jan017333.
I tried,
=TEXT(CONCATENATE(19,AB2,C2),"000000")
even with 11 0's, since the total length is 11. Nothing changes.

Try the following:
=CONCATENATE(LEFT(AB2,5),TEXT(RIGHT(AB2,LEN(AB2)-5),"000000"))
It will basically, take the first 5 characters and concatenate that with the remaining characters formatted as a six digit number with leading zeroes

If your identifier is on A1, you can try this:
=IF(LEN(A1)<11;CONCATENATE(LEFT(A1;5);RIGHT("000000"&MID(A1;6;5);6));A1)
See what happens.

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)

Add leading 0 after the dash (-) but before the numbers

I have a formula that adds a 0 before the numbers 1-9 if they don't have one.
Old..................New
D-8..................D-08
FE-09..............FE-09
I-18..................I-18
P-1..................P-01
FG-08A...........FG-08
=LEFT(A1,FIND("-",A1))&TEXT(MID(A1,FIND("-",A1)+1,2),"00")
However, for values like FG-08A, I do not want it to clear the A at the end. So if it's FG-08A, the result would be FG-08A (remain unchanged). If it's FG-8A, it would be FG-08A (adds the leading 0 but keeps the "A").
Add check for the ending letter:
=LEFT(A1,FIND("-",A1))&TEXT(MID(A1,FIND("-",A1)+1,ISNUMBER(--MID(A1,FIND("-",A1)+1,2))+1),"00")&IF(ISERROR(--RIGHT(A1)),RIGHT(A1),"")
As stated in my comment, if you never have more than two consecutive numbers and if these will never be 00, you can use:
=SUBSTITUTE(SUBSTITUTE(A1,"-","-0"),"00","0")

PowerQuery M Conditional Column 'count' argument is out of range

I have a sheet with dates as MMDDYYY with no leading 0's if month number is single digit. For example, 1012018 or 12312018. Each record has a date, and each date is either 7 or 8 characters in length.
Here is the code I am using to convert the numbers to dates:
if Text.Length([ContractDate]) = 7
then
Text.Range([ContractDate],0,1)&"/"&Text.Range([ContractDate],1,2)&"/"&Text.Range([ContractDate],4,4)
else
Text.Range([ContractDate],0,2)&"/"&Text.Range([ContractDate],2,2)&"/"&Text.Range([ContractDate],4,4)
The code works fine for the "else" condition but I am getting error "Expression.Error: The 'count' argument is out of range. Details: 4" for all records where Text.Length() = 7. I verified this by adding a second column to get Length of ContractDate.
What am I missing?
EDIT: Problem Solved - I'm an idiot. I was getting an error because in the "then" condition, I am extracting a substring of (4,4) from a value that only has Len=7. I can't get 4 characters out of a 7 character string when starting at index of 4.
I know you found the issue with your code, but worth pointing out some things that might be good to know.
Text.Range with no character count will pull in all characters past the start point (so Text.Range([ContractDate], 4) would work for both).
Text.Middle operates like Text.Range but will not cause an error if you select a range that expands past the size of the string. This can be useful if for some reason you were dealing with variable size strings where you need a specific number of characters up to a limit past a certain position.
You could also use Text.PadStart([ContractDate], 8, "0") to pad the 7 length strings with a 0 at the start, and avoid the need for a conditional check all together.

=IF(ISNUMBER(SEARCH.... the difference between 1 and 11

I am trying to convert a single column of numbers in excel to multiple depending on the content.
e.g. Table 1 contains 1 column that contains 1 or more numbers between 1 and 11 separated with a comma. Table 2 should contain 11 columns with a 1 or a 0 depending on the numbers found in Table 1.
I am using the following formula at present:
=IF(ISNUMBER(SEARCH("1",A2)),1,0)
The next column contains the following:
=IF(ISNUMBER(SEARCH("2",A2)),1,0)
All the way to 11
=IF(ISNUMBER(SEARCH("11",A2)),1,0)
The problem with this however is that the code for finding references to 1 also find the references to 11. Is it possible to write a formula that can tell the difference so that if I have the following in Table 1:
2, 5, 11
It doesn't put a 1 in column 1 of Table 2?
Thanks.
Use, for list with just comma:
=IF(ISNUMBER(SEARCH(",1,", ","&A2&",")),1,0)
If list is separated with , (comma+space):
=IF(ISNUMBER(SEARCH(", 1,", ", "&A2&",")),1,0)
A version of LS_dev's answer that will cope with 0...n spaces before or after each comma is:
=IF(ISNUMBER(SEARCH(", 1 ,",", "&TRIM(SUBSTITUTE(A2,","," , "))&" ,")),1,0)
The SUBSTITUTE makes sure there's always at least one space before and after each comma and the TRIM replaces multiple spaces with one space, so the result of the TRIM function will have exactly one space before and after each comma.
How about using the SUBSTITUTE function to change all "11" to Roman numeral "XI" prior to doing your search:
=IF(ISNUMBER(SEARCH("1",SUBSTITUTE(A2, "11", "XI"))),1,0)
If you want to eliminate "11" case, but this is all based on hardcoded values, there should be a smarter solution.
=IF(ISNUMBER(SEARCH(AND("1",NOT("11")),A2)),1,0)

how to extract 10 digit number from column excel

I have column which consists of text including 13 digit number. How Can I keep 10 digit number and delete all other text?
Please help me I am new to excel..
thanks in advance
Edited:
Cell Format
[6/11/2013 3:26:37 PM] 1234503776599, ksdfl 038ddf63Ksdf)
[6/12/2013 3:26:37 PM] 0234503664599, ksdfadssdfl 038ddf6dfsd3Ksdf)
[6/13/2013 3:26:37 PM] 7234503666099, 45sdsdfadssdfl 03845ddf6dfsd3Ksdf)
Here, In second column I want to keep 13 digit and delete all text after that 13 digit.
Is the number always at the beginning of the cell? If so you can use =LEFT(cell_ref, 10) to extract the first 10 characters, which in this case are numbers and will be treated as such by the spreadsheet.
I'm guessing you will need something like this
=MID(A1,32,FIND(",",A1,32) -32)
MID will get text from the middle of a string
FIND will get the location of the first comma
Thinking that the 13 digit number is in the middle of the string, with 9 spaces to the left and a comma to the right we can use the following formula in a separate cell:
=MID(A1,LEN(LEFT(A1,FIND("]",A1)+1))+9,13)
The LEN function determines the length of the part up to and including ] (big bracket). Then the number 9 is added to include nine spaces. Then the number 13 is the length of the 13 digit number. All these are used as parameters for the MID function.
After you get the result just drag down using the autofill handle to get the mid 13 digit number for all the rows.
=LOOKUP(10^11,MID(A1,ROW(INDIRECT("1:"&LEN(A1)-9)),11)+0)
This works for me.
To extract 6 continuous numeric digits, use the below code:
=LOOKUP(10^6,MID(A1,ROW(INDIRECT("1:"&LEN(A1)-5)),6)+0)
Replace 6 in the above code with the number of digits that are required to be extracted.

Resources