I've found some tools that can do what I want, but despite trying various options I can't work out how to put them in my existing formula!
I'm trying to generate an invoice reference number, which would look like 'ABC000012' - with the first row being ABC000001 and increasing in number as each row is added. I can currently generate 'ABC1' and so on, but can't work out how to add the preceding 0s.
I'm currently using CONCATENATE as follows:
=IF(ISBLANK(B2),,CONCATENATE("ABC",(ROW(1:1))))
What do I need to add to this, and where, in order to get the references I'm looking for?
I'm also happy to be advised that I should change the whole formula if there's something different that will work better
Thanks
Use TEXT() to set the preceding 0:
=IF(ISBLANK(B2),"",CONCATENATE("ABC",TEXT(ROW(1:1),"000000")))
=IF(ISBLANK(B2),"","ABC"&RIGHT("000000"&ROW(1:1),6))
This is based off Scott Craner's answer. The difference is that is will limit the number of digits in your invoice to 6 characters. if you want it to always be 8 characters long change the 6 to an 8 and increase the number of 0 between the " ". Alternatively you could also do:
=IF(ISBLANK(B2),"","ABC"&RIGHT(rept(0,6)&ROW(1:1),6))
In the above formula to change the number of digits n the invoice number, you would need to change both 6's
Caveat:
If there is a blank cell in the middle of your list, that number will be skipped for each blank cell. To avoid this, you will need a different counting method than row(1:1).
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.
Is it possible to count the number of individual entries in a cell?
For example 2+2+4-1 = 4 entries
Using the count formula counts the entries as 1
I want to calculate the number of adjustments made in a particular period.
Each +/- in an individual cell represents 1 adjustment.
Assuming you're referring to a text cell, the trick is to count the symobols you'd like to find. Before we dig into that, if you want to enter this data as text, you can use the ` symbol (Usually to the left of the 1 key on your keyboard) before entering your text to make sure it gets processed as text.
If you want to verify that it is text, you can use the TYPE function and look for a return result of 2 (check the link for other possible return types)
There are no direct functions to count characters in Excel, so the trick is to find the length of the original text and subtract it from the length of a new text where you have removed all of the special characters. You mentioned you were trying to count the entries (i.e. the numbers), but you said your goal was to ultimately count the number of '+/-' operations. Since counting numbers can be tricky with excel formulas (since we'll get hung up on 2 and 3 digit numbers), I am going to approach this problem from the perspective of counting the operations you are looking for. So here is a basic example:
length("2+1") = 3
- length("21") = 2 (we replaced the + with "" [blank])
= 1
So we know there is 1 '+' since we replaced it. The appropriate functions used to accomplish this are LEN and SUBSTITUTE
Since you can only find one symbol at a time using the SUBSTITUTE function, we must take the output of the first formula, and give it to the second formula, and so on and so forth. Ultimately, we can put together as many functions as we need to achieve the desired result.
So we start with + for your example (And assuming your data is in A1)
=LEN(A1)-LEN(SUBSTITUTE(A1,"+",""))
which gives us a result of 2. But we also need to find the - symbol. So we wrap another SUBSTITUTE:
=LEN(A1)-LEN(SUBSTITUTE(SUBSTITUTE(A1,"+",""),"-",""))
You have said you wanted to count the number of +/- in the cell, and this does accomplish that, but if you want to expand it to more mathematical operators, you simply add more SUBSTITUTE functions (here is a complete function where I've added * and /)
=LEN(A1)-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"+",""), "-",""),"*",""),"/",""))
Well, this formula would replace all your numbers with "" and then Count the +/- and adds one, should do it, but is ugly:
=LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1;"0";"");"1";"");"2";"");"3";"");"4";"");"5";"");"6";"");"7";"");"8";"");"9";""))+1
Could probably be done with RegEx, but I don't know how to do that in formulas
This makes 31+12+3-4 to ++-, Counts the LEN (3) and adds 1
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
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 vaguely remember that it is possible to parse the data in a cell and keep only part of the data after setting up certain conditions. But I can't remember what exact commands to use. Any help/suggestion?
For example, A1 contains the following info
0/1:47,45:92:99:1319,0,1320
Is there a way to pick up, say, 0/1 or 1319,0,1320 and remove the rest unchosen data?
I know I can do text-to-column and set the delimiter, followed by manually removing the "un-needed" data, but my EXCEL spreadsheet contains 100 columns X 500000 rows with each cell looking similar to the data above, so I am afraid EXCEL may crash before finishing the work. (have been trying with LEFT, LEN, RIGHT, MID, but none seems to work the way I had hoped)
Any suggestion will be greatly appreciated.
I think what you are looking for is combination of find and mid, but you'll have to work out exactly how you want to split your string:
A1 = 0/1:47,45:92:99:1319,0,1320 //your number
B1 = Find(“:“,A1) //location of first ":" symbol
C1 = LEN(A1) - B1 //character count to copy ( possibly requires +1 or -1 after B1.
=Left(A1,B1) //left of your symbol
=Mid(A1,B1+1,C1) //right size from your symbol (you can also replace C1 with better defined number to extract only 1 portion
//You can also nest the statements to save space, but usually at cost of processing quantity increase
This is the concept, you will probably need to do it in multiple cells to split a string as long as yours. For multiple splits you probably want to replicate this command to target the result of previous right/mid command.
That way, you will get cell result sequence like:
0/1:47,45:92:99:1319,0,1320; 47,45:92:99:1319,0,1320; 92:99:1319,0,1320; 99:1319,0,1320......
From each of those you can retrieve left side of the string up to ":" to get each portion of a string.
If you are working with a large table you probably want to look into VB scripting. To my knowledge there is no single excel command that can take 1 cell and split it into multiple ones.
Let me try to help you about this, I am not a professional so you may face some problems. First of all my solution contains 2 columns to be added to the source column as you can see below. However you can improve formulas with this principle.
Column B Formula:
=LEFT(A2,FIND(":",A2,1)-1)
Column C Formula:
=RIGHT(A2,LEN(A2)-FIND("|",SUBSTITUTE(A2,":","|",LEN(A2)-LEN(SUBSTITUTE(A2,":","")))))
Given you statement of having 100x columns I imagine in some instances you are needing to isolate characters in the middle of your string, thus Left and Right may not always work. However, where possible use them where you can.
Assuming your string is in cell F2: 0/1:47,45:92:99:1319,0,1320
=LEFT(F2,3)
This returns 0/1 which are the first 3 characters in the string counting from the left. Likewise, Right functions similarly:
=RIGHT(F2,4)
This returns 1320, returning the 4 characters starting from the right.
You can use a combination of Mid and Find to dynamically find characters or strings based off of defined characters. Here are a few examples of ways to dynamically isloate values in your string. Keep in mind the key to these examples is the nested Find formula, where the inner most Find is the first character to start at in the string.
1) Return 2 characters after the second : character
In cell F2 I need to isolate the "92":
=MID(F2,FIND(":",F2,FIND(":",F2)+1)+1,2)
The inner most Find locates the first : in the string (4 characters in). We add the +1 to move to the 5th character (moving beyond the first : so the second Find will not see it) and move to the next Find which starts looking for : again from that character. This second Find returns 10, as the second : is the 10th character in the string. The Mid formula takes over here. The formula is saying, Starting at the 10th character return the following 2 characters. Returning two characters is dictated by the 2 at the end of the formula (the last part of the Mid formula).
2) In this case I need to find the 2 characters after the 3rd : in the string. In this case "99":
=MID(F2,FIND(":",F2,FIND(":",F2,FIND(":",F2)+1)+1)+1,2)
You can see we have simply added one more nested Find to the formula in example 1.