Ok so I had a nice formula until a problem came along. Basically I needed to get rid off a zeros in the middle of a 10 characters String/Range i.e AB00005879 to do that I have used formula SUBSTITUTE(NameRange,"0","") which gave me nice AB5879 solution. Sometimes the number at the end would only be 3 digit long AB00000975 so my formula would give me AB975 All great until I stumble a problem. Some of the strings came in a form of i.e. AB00004020 So my formula extracted every zero leaving me with AB42. Is there a way to extract only first four zeros in a middle an always keep the number at the and? so the last scenario would look like AB4020. Thanks in advance
SUBSTITUTE(NameRange,"0",""))
If you always have two characters at the start and then some zeros and then some numbers, all of which you want to keep, this should work
=LEFT(A1,2) & VALUE(RIGHT(A1,LEN(A1)-2))
EDIT #2
If your string always starts with two letters such as AB following by a random number of zeros and then a number string that you want to keep, try
=LEFT(A1,2)&RIGHT(A1,11-AGGREGATE(15,6,ROW($3:$10)/(--MID(A1,ROW($3:$10),1)>0),1))
Replace A1 with your actual case.
Related
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.
First off, thank you to all how have helped get me to this point. I'm so close! On to the scenario, which I apologize in advance is a bit of a work in progress.
I have text in a cell and I need to extract a number. The tricky part is there are various situations to address.
The number may immediately follow a "#" and could vary in length. People on Stack Overflow helped me with coming up with this which works great:
MID(B2,(FIND("#",B2,1)+1),FIND(" ",B2,FIND("#",B2,1)+1)-FIND("#",B2,1))
That was a huge leap forward, but there are also situations where there is no # sign and the cell might have "abc (1205) 645 chan", where I need to extract the 645.
I'm using this, below, in conjunction with an on error statement for when there is no "#"
TRIM(MID(B53,(FIND(" " &{"1","2","3","4","5","6","7","8","9"},B53,1)),FIND(" ",B53,FIND({"1","2","3","4","5","6","7","8","9"},B53,1))-FIND({"1","2","3","4","5","6","7","8","9"},B53)))
So I use the first Mid/Find to avoid the (1205) and find the next " x" where x is a number. The problem is it seems I have trouble when the number I'm searching for has 1 or 3+ numbers in it, but if it has 2 I return the value just fine.
It seems I'm very close but just not there yet.
This formula will return the number that follows either a # or a ) in your string. If that pattern does not exist, it will return a #NUM!` error
=AGGREGATE(14,6,--MID(A1,MIN(FIND({"#",")"},A1&"#)"))+1,{1,2,3,4,5}),1)
Note the array constant as the num_chars argument of the MID function. The maximum number should be at least the largest number of digits (or decimal + digits) plus any spaces between the delimiter and the first digit, that might be expected to be found.
EDIT: If your version of Excel is prior to 2010, and does not have the AGGREGATE function, you may use this array-entered formula instead, so long as the values to be returned will be positive numbers:
=MAX(IFERROR(--MID(A1,MIN(FIND({"#",")"},A1&"#)"))+1,{1,2,3,4,5}),0))
This formula must be entered by holding down ctrl+shift while hitting enter
I have a column (F) full of 11 digit numbers, what I need is to split them like the following: 12,345,6789,00
I have the following formula which adds a comma after the first two digits however I don't know how to get it to add them in after the next 3 then 4.
=LEFT(F2,2)&","&MID(F2,3,LEN(F2))
The above formula outputs like this: 12,345678900
Any suggestions?
Have you considered using the TEXT function? This is simple and would do the trick:
=TEXT(F2,"00"",""000"",""0000"",""00")
Use MID all the way:
=MID(F2,1,2)&","&MID(F2,3,3)&","&MID(F2,6,4)&","&MID(F2,10,2)
=left(F2,2)&","&mid(F2,3,3)&","&mid(F2,6,4)&","&right(F2,2)
Will give you what you want.
=LEFT(F2,2) &","&MID(F2,3,3)&","&MID(F2,6,4)&","&RIGHT(F2,2)
Try using the Text to Columns function in the Data Tab of Excel. It will allow you to split the numbers based on number of digits. For this to work though, it needs to be the case that the number ALWAYS has 11 digits... otherwise some numbers will get cut in the wrong spot.
You can then Concotenate them back together with Commas inbetween.
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.
I have something like this:
A1: ABC-DE442
B1: 0069-1234-12
I'm trying to make a formula that will look at A1, get the number 442, and then check if B1 is in the format of 4 numbers, a dash, 4 numbers, a dash, and then finally 2 numbers. I want to make sure that this could work with any number besides 442 though. So if I had like 123 instead of 442, it would need to be 1 number, dash, 2 numbers, dash, and three numbers.
It would also need to give me an error if I had something like this:
A1: ABC-DE442
B1: 004-2345-34
because it only has three numbers in the first section before the dash.
Hopefully I have been clear enough in what I'm trying to do. Any help would be greatly appreciated.
So in the end, this is the giant formula I had to create:
=IF(LEN(LEFT(J4,FIND("-",J4)-1))=VALUE(MID(I4,9,1)),IF(LEN(LEFT(MID(J4,FIND("-",J4)+1,999),FIND("-",MID(J4,FIND("-",J4)+1,999))-1))=VALUE(MID(I4,10,1)),IF(LEN(MID(MID(J4,FIND("-",J4)+1,999),FIND("-",MID(J4,FIND("-",J4)+1,999))+1,999))=VALUE(MID(I4,11,1)),"True","Doesn't match code part 3"),"Doesn't match code part 2"),"Doesn't match code part 1")
J15: 0069=LEFT(J5,FIND("-",J5)-1)
J16: 4=VALUE(MID(I5,7,1))
J17: 4=LEN(J15)
J18: 0469-56=MID(J5,FIND("-",J5)+1,999)
J19: 0469=LEFT(J18,FIND("-",J18)-1)
J20: 4=VALUE(MID(I5,8,1))
J21: 4=LEN(J19)
J22: 56=MID(J18,FIND("-",J18)+1,999)
J23: 2=VALUE(MID(I5,9,1))
J24: 2=LEN(J22)
Hopefully all of these formulas will make it easier to understand how I combined everything together.
I essentially put every formula into one giant one using the information used in the answer I said was right. For the first part, I took the LEN(D1) but had it all written out, and then set it equal to the =VALUE(MID(A1,7,1)).
Then, for the true part of that if statement, I had to first get A1 without D1, then get it to just be the middle section using the LEFT formula, and then finally taking the LEN of that. Checked to see if it was equal to the =VALUE(MID(I4,10,1)), which was the next number in B1.
If that was true, I went to the final IF statement which again had to go through the same process of getting the last section of A1 on it's own, taking the length of that, and seeing if it was equal to =VALUE(MID(I4,11,1)).
Finally, I just created different print statements for the last true, and every false section of the IF statements.
Moral of the story, I was able to make a formula that works with every single number combination because it turns out B1 could only be in the form of AB - CDE###, so I could always find that number in B1 and compare it.
This should be possible with Excel formulae but it will get a bit complicated. The functions you're probably going to want to make use of are FIND, LEFT, LEN, MID, and VALUE.
For example,
C1: =FIND("-",B1)
will return the position of the first dash in the string to be tested, which for your example is 5. Then
D1: =LEFT(B1,C1-1)
would return the characters before that dash, i.e. '0069'. Meanwhile you need to get the lengths of the three runs of digits out of your first string (the one in A1). Will that string always be the same length? If so you can use e.g.
=VALUE(MID(A1,7,1))
which returns the 7th character of the string in A1 and converts it to a number (4). Now you can test whether that value is equal to the length of the first run of characters, i.e. LEN(D1).
But are those characters all numeric? Well, you can try converting them to a number with VALUE(D1) which will return #VALUE if the argument can't be made into a number.
OK, that checked the first run of characters, what about the rest of them? Well,
=MID(B1,FIND("-",B1)+1,999)
will give you the remainder of the original string after the first dash, which you can analyse in the same way, and so on.
It's easiest to develop these formulae by using lots of cells to hold the intermediate values as you work them out, but once you're confident these are working OK you can consolidate them into fewer cells. Whatever you come up with, make sure you test it with lots of different inputs to check that your formulae respond to them in the way that you expect. (In particular, check what happens if you have one or more spaces after a dash, as VALUE will ignore leading spaces - you might want to use a SUBSTITUTE function on your initial text to remove any spaces.)