Concatenate Custom Function - excel

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.

Related

Removing first two digits in Excel if the character length is greater than certain number

I have cell phone numbers in Excel some with country code- 91 and some without country code. I need to remove the country code. We have 10 digit phone numbers so I need to remove the first two digits if the character length of the cell is greater than 10, i.e. if I have a number with country code like 917465785236 I need to remove the first two digits- 91 so that I only have 7465785236. I am trying the below piece but it doesn't check the IF condition and removes the first two digits from all the cells. Can someone tell me what's wrong I am doing here:
=IF((LEN(A1>10)),RIGHT(A1, LEN(A1)-2))
You probably need to put the parentheses differently for the Len function:
=IF((LEN(A1)>10),RIGHT(A1, LEN(A1)-2))
You're not using the parenthesis properly. Also since you strictly want to have 10 characters, you don't need to calculated the length in the RIGHT formula.. It needs to be like this:
=IF(LEN(A1)>10,RIGHT(A1, LEN(A1)-2),A1)
Now, that is the issue with your formula, but the solution to your question doesn't even need a IF statement, You can simply use:\
RIGHT(A1,10)
It will automatically get the 10 characters at the end and remove the rest.

How to select a few numbers from a given number

If I have entered a certain 4 digit number for example ,1234 how do I choose like the first 2 numbers or the last two numbers from the cell by that i mean suppose i want it to return 34 for the last two digits and I want it to return 12 for the first two digits. So anytime I change my 4 digit number it works the same way.
You may use the LEFT and RIGHT functions, e.g.
=LEFT("1234", 2)
=RIGHT("1234", 2)
If your 4-digit number is, in fact, a string you can parse the string as suggested by #Tim Biegeleisen. In my Excel 365, when I enter 1234 in a cell formatted as General I can use the same method.
=LEFT(A1, 2)
and
=Right(A1, 2)
However, this conversion of a number to text mustn't be presumed to work under all circumstances. Therefore you may prefer to convert the number to text explicitly in the formula.
=LEFT(TEXT(A1,"0000"), 2)
and
=Right(TEXT(A1,"0000"), 2)
This method has the added advantage of being able to handle numbers of less than 4 digits.
On the other hand, you can also extract first and last digits from a true number, without converting it to text.
=INT(A1/100)
and
=MOD(A1,100)
The main difference is that the results are also numbers (all partial strings are text). Therefore this would be the preferred method if you don't want to worry about strings, text, numbers, numerics and cell formats.

Extracting certain numbers from a cell containing numbers and special characters

I have cells that contain both numbers and special characters such as this:
[1:250:10]
The 'coordinates' shown above can be in the following format.
[(1-9):(1-499):(1-15)] in terms of what numbers can be within each part.
How do I extract these three numbers into three separate cells?
Assuming your data is in Cell A1 the to extract first number use following formula
=MID(A1,2,(FIND(":",A1,1)-2))
for second number use
=SUBSTITUTE(MID(SUBSTITUTE(":" & A1&REPT(" ",6),":",REPT(":",255)),2*255,255),":","")
finally for third number enter
=SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(A1,":",REPT(" ",LEN(A1))),LEN(A1))),"]","")
Just tossing out some other options.
First number since it only has a length of 1 digit and is on the left side, use the following:
=RIGHT(LEFT(A1,2))
second number will be found by locating the : in the string
=MID(A1,FIND(":",A1)+1,FIND(":",A1,FIND(":",A1)+1)-(FIND(":",A1)+1))
third number will be dealt with in the same way as the second but we will use the second : and the ] as the identifiers as to where to grab from and how much to pull.
=MID(A1,FIND(":",A1,FIND(":",A1)+1)+1,FIND("]",A1)-(FIND(":",A1,FIND(":",A1)+1)+1))
now all those number will actually come through as text. If you want to have them as numbers in the cells, send them through a math operation that will not change their value. Do something like +0, -0, or *1 at the end. Alternatively you could add -- at the start of each formula (yes that is double - incase you were wondering if it was a typo)

data validation with numbers + text

Trying to write a custom data validation formula that would only allow values in the following format: 2-digit year (this can be just 2 numbers), dash ("-"), then a 1 or 2 letter character(s) (would prefer upper case, but would settle for lower case), another dash ("-"), and then a 5-digit number. So the final value looks like: 17-FL-12345 ...or 16-G-00008...
I actually have a but more, but if I could get the above working, that would be terrific. I don't know if there's a way, but it would be great if additionally I could use custom formatting to get the dashes to appear when they are not entered, i.e., user enters "17FL12345" and it gets automatically formatted to "17-FL-12345". Finally, again, this isn't a deal breaker either, but it would also be great if the last 5 digits would add any leading zero's, i.e., the user enters 17-G-8 (or just 17G8) and it gets formatted to 17-G-00008.
Can't use VBA unfortunately. Some potential solutions to similar questions I've viewed include:
https://www.mrexcel.com/forum/excel-questions/615799-data-validation-mixed-numeric-text-formula-only.html
Data VAlidation - Text Length & Character Type
Excel : Data Validation, how to force the user to enter a string that is 2 char long?
Try this:
=AND(ISNUMBER(VALUE(LEFT(A1,2))),MID(A1,3,1)="-",OR(ISNUMBER(FIND(MID(A1,4,1),$C$1)),AND(ISNUMBER(FIND(MID(A1,4,1),$C$1)),ISNUMBER(FIND(MID(A1,5,1),$C$1)))),MID(A1,LEN(A1)-5,1)="-",ISNUMBER(VALUE(RIGHT(A1,5))),OR(LEN(A1)=11,LEN(A1)=10),LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))=2,LEN(A1)-LEN(SUBSTITUTE(A1,"+",""))=0,LEN(A1)-LEN(SUBSTITUTE(A1," ",""))=0)
Assuming, you want to validate A1. I inserted the letters in C1.
Edit:
I edited the original function, to be more secure and left out the Isnumber part and rather went digit by digit.
If you want exceed the 255 limit, you have to slice the function up.
I created 5 functions.
=AND(ISNUMBER(FIND(LEFT(A1),$C$2)),ISNUMBER(FIND(MID(A1,2,1),$C$2)))
=MID(A1,3,1)="-"
=IF(LEN(A1)=10,AND(ISNUMBER(FIND(MID(A1,4,1),$C$1)),MID(A1,5,1)="-"),IF(LEN(A1)=11,AND(ISNUMBER(FIND(MID(A1,4,1),$C$1)),ISNUMBER(FIND(MID(A1,5,1),$C$1)))))
=IF(LEN(A1)=10,MID(A1,5,1)="-",IF(LEN(A1)=11,MID(A1,6,1)="-"))
=IF(LEN(A1)=10,AND(ISNUMBER(FIND(MID(A1,6,1),$C$2)),ISNUMBER(FIND(MID(A1,7,1),$C$2)),ISNUMBER(FIND(MID(A1,8,1),$C$2)),ISNUMBER(FIND(MID(A1,9,1),$C$2)),ISNUMBER(FIND(MID(A1,10,1),$C$2))),IF(LEN(A1)=11,AND(ISNUMBER(FIND(MID(A1,7,1),$C$2)),ISNUMBER(FIND(MID(A1,8,1),$C$2)),ISNUMBER(FIND(MID(A1,9,1),$C$2)),ISNUMBER(FIND(MID(A1,10,1),$C$2)),ISNUMBER(FIND(MID(A1,11,1),$C$2)))))
Set up data validation as on the picture:

Excel Number Formatting

I'm currently working on a sheet that contains part numbers in it. I'd like them to be formatted like this:
####-#####-XX
Where #s can be letters or numbers, #s are numbers, and Xs are letters.
I run into two problems while doing this. The first is that I can't figure out how to handle text and numbers at the same time in the Custom Format dialog box. The second is that occasionally a part number will have 3 letters after the second hyphen rather than 2, and I can't figure out how I should structure the condition to differentiate between the two formats.
How can I handle numbers and text at the same time when creating a custom format, and how can I add the condition described above (based on character numbers or something)?
Thanks.
If can't be achieved with custom formatting then a formula such as below may suit:
=LEFT(A1,4)&"-"&MID(A1,5,5)&"-"&RIGHT(A1,LEN(A1)-9)
If the middle number section has to be 5 digits, use
#-0000#-XX
But I don't think number formats are designed to handle Alphanumeric entries, and I can't help you with those X's

Resources