Increment part of alphanumeric string in OpenOffice Calc - excel

I have an alphanumeric string (a serial number) like this
S/N:WLD4450001256790
I was trying to increment it with the classic 'drag&drop' method, but it gaves me strange results, eg.
S/N:WLD4450001256790
S/N:WLD415138135
S/N:WLD415138136
S/N:WLD415138137
S/N:WLD415138138
S/N:WLD415138139
S/N:WLD415138140
S/N:WLD415138141
S/N:WLD415138142
S/N:WLD415138143
I think the problem is due the longness of the number, because when I use an alphanumeric string with a lower number it works:
Example:
S/N:WLD445000
S/N:WLD445001
S/N:WLD445002
S/N:WLD445003
S/N:WLD445004
S/N:WLD445005
S/N:WLD445006
Let's go back to the first alphanumerical string
S/N:WLD4450001256790
Everything but the last 6 numbers is a costant. The only 'incremental' part is 256790.
I'm trying to find a way to create a macro or something where the first part of the alphanumerical string is just a ... 'string' (S/N:WLD4450001) and the rest is a number, hoping to succeed in incrementing it.
Anyone can give a me an advice for that?
I'm pretty new in excel, and i'm reading about macros in these days.
Thanks a lot for your help

In cases like this I like to simplify the problem: I will put the string in column A and the incremental number in column B and the concatenation of the two strings in column C. The operator for the concatenation is &, so:
Type S/N:WLD415 in A1
Type a number in B1
Type =A1&B1 in C1
Select A1:A10 and press Ctrl + D to copy the constant string
Select A2 and drag the little square on the bottom right of the cell down while pressing the Ctrl key to copy and increment (fill series)
Use one of the two ways described above to copy the formula down

In A1 enter:
="S/N:WLD445000" & 1256790+(ROW()-1)
and copy down.

Related

Splitting names given in single cells without using text to column excel

i want to use excel formula to split multiple names given in a single cell. dont want to use text to column feature. For example
in the above yellow is the variable name & the green color is the required format
See find the nth instance of a character: FIND(CHAR(1),SUBSTITUTE(string,delimiter,CHAR(1),nth)). For the first, we use LEFT(string,position_first-1). For the last: RIGHT(string,LEN(string)-position_last). For all in between: MID(string,position_first+1,position_second-position_first-1).
So, combining the logic, we may get this:
=IFERROR(IFERROR(IF(B$1=1,LEFT($A2,FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),1),1)-1),MID($A2,FIND(CHAR(160),SUBSTITUTE($A2,"/",CHAR(160),B$1-1),1)+1,FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),1+B$1-1),1)-FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),B$1-1),1)-1)),RIGHT($A2,LEN($A2)-FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),B$1-1),1))),"")
IFERROR(...,"") is used to return "" after last occurrence (below, in G2). Nested IFERROR(... RIGHT) will be triggered at last occurrence (since MID will fail there; below at F2).
Try using this:
With the full name in cell A2, the formulas go as follows:
Get the first name:
=LEFT(A2,SEARCH(" ",A2)-1)
Get the last name:
=RIGHT(A2,LEN(A2)-SEARCH(" ",A2,1))
You enter the formulas in cells B2 and C2, respectively, and drag the fill handle to copy the formulas down the columns. The result will look something similar to this:

Excel: Using text functions to find the middle

I want to extract Moss Ariel and Murphy from the following strings using text functions in Excel.
Gabriela Moss669.11695-5000-53420000000-1232
Connie Ariel1025.11695-2004-51490000000-1231
Kelly Murphy1040.58695-2200-50630000000-1235
I have a basic grasp with using text functions, but this one has stumped me. Any help is greatly appreciated.
I need to make a formula such that it requires no changes copying it down the list of records.
This would be easier and shorter in Google Sheets or with VBA UDF, but here is another array formula solution (enter it with Ctrl + Shift + Enter) from https://exceljet.net/formula/split-text-and-numbers
=MID(A1,FIND(" ",A1)+1,MIN(FIND(ROW($1:$10)-1,A1&"0123456789"))-FIND(" ",A1)-1)
This might work without array formula:
=MID(A1,FIND(" ",A1)+1,MIN(FIND({0,1,2,3,4,5,6,7,8,9,"."},A1))-FIND(" ",A1)-1)
Say you data begins in A1
First extract the full name with the following formula
[B1] = {LEFT(A1,MATCH(1,--ISNUMBER(--MID(A1,ROW(INDIRECT("A1:A"&LEN(A1))),1)),0)-1)}
This is an array formula, press Ctrl+Shift+Enter after typing formula in B1. Then fill down the formula to the rest of the rows.
Next, simply extract the last name from the full name
[C1] = RIGHT(B1,LEN(B1)-SEARCH(" ",B1))
If you prefer to do it in-one-go here is the formula
[B1] = {MID(A1,SEARCH(" ",A1)+1,MATCH(1,--ISNUMBER(--MID(A1,ROW(INDIRECT("A1:A"&LEN(A1))),1)),0)-1-SEARCH(" ",A1))}
You can use the below formula as it is, no need for array formula to achieve this.
=MID(A1,SEARCH(" ",A1,1)+1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))-SEARCH(" ",A1,1)-1)
You need to combine the functions instr and mid. instr returns the index in a string of the first appearance of a sub-string (or a single character). mid returns a sub-string starting at a given position and with a length of the extracted sub-string. In your case, something like:
MID(MyString,Index(MyString,"Moss"),Len("Moss"))
where MyString holds your source string.

Count the frequency of a specific word in a single cell

In Microsoft Excel I wish to count the frequency of a specific word in a cell. The cell contains a few sentences. I am using a formula right now that is working, but not the way I want it to.
A1
my uncle ate potatos. potato was his favorite food. Don't mash the potato, just keep it simple.
B1 (word to count the frequency of)
potato
C1 (forumula)
=(LEN(A2)-LEN(SUBSTITUTE(A2;B2;"")))/LEN(B2)
C1 Results:
3
In C1, I am getting a count 3. I want it just to be 2. So, the formula is counting potatos.
How do I make the function only count exact matches?
I've got a solution here but it's not pretty.
The problem, as I indicate in my comment, is that Excel has no internal function to see if a cell contains an 'exact match'. You can check if the total value in a cell is an exact match, but you can't check whether a search term has been conjugated like that. So, we'll need to create a special method which checks for every 'acceptable' ending to a word. In my eyes, this would be anything that ends with space, anything that ends with punctuation, and anything at the end of a cell with nothing after it.
ARRAY FORMULAS
You were on the right track with the LEN - SUBSTITUTE method, but the formula will need to be an array formula to work. Array formulas calculate the same thing multiple times over a given range of cells, instead of just once. They resolve the calculation for each individual cell in a formula and provide an array of results. This array of results must be collapsed together to get a single total result.
Consider as follows:
=LEN(C1:C6)
Confirm this formula with CTRL + SHIFT + ENTER instead of just ENTER. This gives us the LEN of C1, followed by C2, C3... etc., resulting in an array of results that looks like this [assume C1 had "a", C2 had "aa", C3 had "a", C4 had "", C5 had "aaa", and C6 had ""]:
={1;2;1;0;3;0}
To get that as a single number providing the total length of each cell individually, wrap that in a SUM function:
=SUM(LEN(C1:C6))
Confirmed again with CTRL + SHIFT + ENTER instead of just ENTER. This results in the total length of all cells: 7.
DEFINING AN EXACT MATCH
Now to take your question, you are looking to find all 'acceptable' matches of given word B1, within text A1. As I said before, we can define an acceptable answer as one which ends in punctuation, a space, or the end of the cell. Something at the end of the cell is a special case which we will consider later. First, take a look at the formula below. In cells C1:C6, I have manually typed a comma, a period, a semi-colon; a hyphen, a space, and a slash. These will be the 'acceptable' ways to end the word found in B1.
=LEN(SUBSTITUTE(A1,B1&C1:C6,""))
Confirmed with CTRL + SHIFT + ENTER, this takes the length of the substitution for the search term in B1 appended with the acceptable word-end in C1:C6. So it gives the length for 6 new SUBSTITUTED words. But as this is an array of results, we need to add them together to get a single number, like so:
=SUM(LEN(SUBSTITUTE(A1,B1&C1:C6,"")))
FORMULIZING THE RESULT
To work it as you have in your sentence, we will now need to subtract this length from the length of the original word. Note that there is a problem with doing this simply - since we are searching multiple times, we will need to add the length of the original word multiple times. Consider something like this:
=LEN(A1)-SUM(LEN(SUBSTITUTE(A1,B1&C1:C6,"")))
This won't work, because it only adds the length of A1 once, but it subtracts the length of the substituted strings multiple times. How about this?
=LEN(A1)*6-SUM(LEN(SUBSTITUTE(A1,B1&C1:C6,"")))
This works, because there are 6 word-end terms we search for with C1:C6, so the substitution there will occur 6 times. So we have the original length of the word 6 times, and the length of each substituted word 6 times [keep in mind that if there is no match for, say, "potato;", then that term will give the length of the original word, thus negating one of the times we added the length of that word, as expected].
To finalize this, we need to divide by the number of letters in the search term. Keep in mind that where you have "/LEN(B1)", we will need to add a character for the length of each of our word-ends.
=(LEN(A1)*6-SUM(LEN(SUBSTITUTE(A1,B1&C1:C6,""))))/(LEN(B1)+1)
Finally, we need to add the special case where the last portion of A1 is equal to the search term, with no word-end. Alone, this would be:
=IF(RIGHT(A1,LEN(B1))=B1,1,0)
This will give us a 1 if the last part of A1 is equal to B1, otherwise it gives 0. So now simply add this to our previous formula, as follows:
=(LEN(A1)*6-SUM(LEN(SUBSTITUTE(A1,B1&C1:C6,""))))/(LEN(B1)+1)+IF(RIGHT(A1,LEN(B1))=B1,1,0)
Remember to confirm with CTRL + SHIFT + ENTER, instead of just ENTER. That's it, it now gives you the count of all "exact matches" of your search term.
ALTERNATE APPROACH TO ARRAY FORMULAS
Note that instead of using C1:C6, you could instead hardcode your formula to look for specific punctuation as the word-end. This will be harder to maintain but, in my opinion, just as readable. It will look like this:
=(LEN(A1)*6-SUM(LEN(SUBSTITUTE(A1,B1&{",",".",";"," ","/","-"},""))))/(LEN(B1)+1)+IF(RIGHT(A1,LEN(B1))=B1,1,0)
This is still technically an "array formula", and it works on the same principles as I have described above. However, one benefit here is that you can confirm this type of entry with just ENTER. This is good, in case someone accidentally edits your cell and presses ENTER without noticing. Otherwise, this is equivilent to the format above.
Let me know if you would like any portion of this elaborated on.
I do have an alternate solution for you to consider. I takes a bit more space and the formulas are a little more convoluted, but in some senses it will be simpler.
Use column C as a new helper column. Column C will take the text from column A, and will substitute out all instances of punctuation with a " ". Once this has been done, the formula to count the instances of the search term from column B will be a simple formula essentially as you have it in your OP.
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,","," "),"."," "),";"," "),"-"," "),"/"," ")
This formula first substitutes all slashes for spaces, then with that substituted text it substitutes dashes for spaces, then with that substited text it substitutes semicolons with spaces, etc. As you indicated, if you use semi-colons as delimiters, you will need to replace my commas separating terms with semi-colons.
Then the formula in D1 is simply what you have above in your OP, with two changes: we will be searching for B1 & " ", because we know all of the 'exact matches' now end in spaces, and we will be adding in an extra '1' if the last part of the text in C1 is the same as the search term in B1 - because if a cell ends in that word, it won't have a space, but it is still an 'exact match'. Like so:
=(LEN(C1)-LEN(SUBSTITUTE(C1,B1&" ","")))/(LEN(B1)+1)+IF(RIGHT(C1,LEN(B1))=B1,1,0)
EDIT
My list of punctuation was only a suggestion; I recommend you really go through some sample text and make sure you don't have any weird characters after words. Also, consider changing uncommon ones I have (like "/", or "-") with "?" or "!". If you want to add more, just follow the pattern of the SUBSTITUTE formula.
To make this case-insensitive, you just need to change the formula in column C to make the result all lower case, and then ensure your search terms in column B are lower case. Change column C like so:
=LOWER(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,","," "),"."," "),";"," "),"-"," "),"/"," "))
Sorry for making it "a new answer". You may move it wherever you want.
I have just found a solution for the answer Liu Kang asked on Aug 3 2015 at 12:15. :)
Unfortunately, I do not have "50 reputation" to comment on Grade 'Eh' Bacon's solution above, where the last comment is this:
Discovered a slight problem. Using =IF(B1<>"";(LEN(A1)-LEN(SUBSTITUTE(A1;B1&" ";"")))/(LEN(B1)+1)+IF(RIGHT(A1;LEN(B1))=B1;1;0);"") with shoe in B1 gives the following result: shoe in A1 = 1 (correct), shoes in A1 = 0 (correct), ladyshoe in A1 = 1 (wrong). Guess this have to do with "RIGHT" in the formula. Is it possible to make the formula non-matching for prefix words? E.g if B1 is containing shoe and A1 is containing ladyshoe dogshoe catshoes shoes I want C1 to result in 0. – Liu Kang Aug 3 '15 at 12:15
The solution is to search for a space at the beginning of the word as well (" "&B1&" ") and to add "one" more LEN(B1)+2. So, it becomes =IF(B1<>"";(LEN(A1)-LEN(SUBSTITUTE(A1;" "&B1&" ";"")))/(LEN(B1)+2)+IF(RIGHT(A1;LEN(B1))=B1;1;0);"").
There is one more problem if the word we are looking for is at the beginning. Because there is obviously no space " " at the beginning of the sentence. I use a workaround for it - I have my sentence in A1, but then I have a hidden column B where there is =" "&A1 in B1 and it puts the "space" I need to the beginning of the sentence and everything from the original Grade 'Eh' Bacon's solution is shifted (A1->B1, B1->C1, C1->D1).
I hope it can help and thanks to all who participated in this thread, you helped me A LOT!
Do you need this to be a single formula? I have an idea, but it takes a few (relaitvely simple) steps.
Since you have a long sentence in A1, what about going to Data -> Text to Columns, and send this sentence into a Row, delimited by spaces. Then, remove any punctuation. Then, just do a simple Countif()?
Put the info in A1, then go to Data --> Text to Columns, choose "Delimited", click Next, and choose "Space":
Click Finish, and it'll put the entire thing into Row 1, with a word in each cell. Now just Find/Replace "." and "," with nothing.
Then, Countif to the rescue!
If that works, we can automate into VB, so you don't have to manually find/replace the puncutation. Before I jump into that, does this method work?
Take the length of the string and minus the length of the string with the keyword replaced with nothing then divide the result by the length of the keyword:
=(LEN(A1)-LEN(SUBSTITUTE(A1,B1,"")))/LEN(B1)

Excel find text value in string

I have a string such as K68272CAA6A1
And need to do that, formula will pass the first character (I mean string will be 68272CAA6A1 in mind) and formula will find the first text character. And cell value will be 7. Because first text character is "C" and it's the 7th character of my string (include "K" character).
And after that I'll split rest of them. But I'm confused about this issue.
If I understand you correctly, you are looking for the position of the 2nd letter in your string. That number is given by the following array-entered formula.
To enter an array formula, hold down ctrl+shift while hitting Enter. If you do this correctly, in the Formula Bar you will see braces {...} around the formula:
=MATCH(FALSE,ISNUMBER(MID(A1,ROW(INDIRECT("2:99")),1)/1),0)+1
The 99 just needs to be some number larger than the length of your longest string.
If I understood you correctly, a formula that implements this functionality (assuming cell A1 = K68272CAA6A1 and B1 = K) would be:
=FIND(RIGHT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(RIGHT(A1,LEN(A1)-FIND(B1,A1)),"1",""),"2",""),"3",""),"4",""),"5",""),"6",""),"7",""),"8",""),"9",""),1),RIGHT(A1,LEN(A1)-FIND(B1,A1)))-1
The long sequence of substitute is there to remove the numbers (I couldn't find a specific formula to remove them).
This gigantic formula for your example would simply give the answer 6.
To get the strings separated as you want all you need to do is =LEFT(A1,D1) supposing the long formula is on D1 and =RIGHT(A1,D1), which in your example would yield respectively K68272 and CAA6A1

String Separate in Excel

mozilla-nss-3.11.4-0.7
gdb-10.12-1.5.2
glibc-dcc-atv-1.0.3-10.6
i want to separate it too in the next B C D cell
mozilla-nss 3.11.4 0.7
gdb 10.12 1.5.2
glibc-dcc-atv 1.0.3 10.6
right now i can use left , right and find function to do it but not quite work well
i use
LEFT(B33,FIND(".",B33)-2) =B cell
RIGHT(B33,FIND(".",B33)) =C Cell
RIGHT(D33,FIND("-",D33)-1) = D Cell
answer is not right anyone can Help me correct my function thank you
The key point here which makes the task difficult - we need to use as separators LAST TWO hyphens in the string, and remain all the rest intact. For such cases ARRAY formulas is the best shot. My solution is below:
Name 6 columns starting A1: String | MAX "-" | 2nd MAX "-" | Str1 | Str2 | Str3
Put your values in Column A starting at A2.
B2 (MAX "-"): type the formula =MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)) but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
C2 (2nd MAX "-"): type the formula =MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)*IF(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)=MAX(IFERROR(SEARCH("-",$A2,ROW(INDIRECT("1:"&LEN($A2)))),0)),0,1)) and again press CTRL+SHIFT+ENTER.
Thus we'll obtain positions of LAST TWO hyphens in the string. The rest is easy - ordinary LEFT / MID / RIGHT stuff:
D2: =LEFT($A2,$C2-1), ENTER.
E2: =MID($A2,$C2+1,$B2-$C2-1), ENTER.
F2: =RIGHT($A2,LEN($A2)-$B2), ENTER.
Autofill B:F.
If temporary columns B:C are unwanted - you should replace references to them in D:F for B:C contents (i.e. replace $A2 in =LEFT($A2, with A2 actual formula), but this will result in TOO complicated ARRAY formulas, still doing their job - but difficult to understand the next day even for the creator)
As for the above solution - perhaps it might be improved or simplified, but I'm pretty much familiar with such ROW...INDIRECT constructions from times I had to analyze megabytes of statistic data, so for me it's just as easy as create LEFT / RIGHT. Anyway, it seems to work.
For your convenience my sample file is shared: https://www.dropbox.com/s/p49x32t3a0igtby/StringHyphensSeparate.xlsx
Hope that was helpful)
ADDITION - 2 more simplified solutions to find LAST TWO hyphens (the rest of steps is the same as above):
More simple ARRAY formulas:
B2 (MAX "-"): type the formula =MAX(IF(MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1)="-",ROW(INDIRECT("1:"&LEN($A2))),0)) but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {} brackets around it (but do NOT type them manually!).
C2 (2nd MAX "-"): type the formula =LARGE(IF(MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1)="-",ROW(INDIRECT("1:"&LEN($A2))),0),2) and again press CTRL+SHIFT+ENTER.
Regular formulas using SUBSTITUTE function:
B2 (MAX "-"): type the formula =SEARCH("#",SUBSTITUTE($A2,"-","#",LEN($A2)-LEN(SUBSTITUTE($A2,"-","")))), ENTER.
C2 (2nd MAX "-"): type the formula =SEARCH("#",SUBSTITUTE($A2,"-","#",LEN($A2)-LEN(SUBSTITUTE($A2,"-",""))-1)), ENTER.
The key for SUBSTITUTE solution is that it may replace only certain instances of matches, i.e. only 2nd or 3rd hyphen. The overall number of hyphens is determined again via SUBSTITUTE formula: length of original string MINUS length of string with ALL hyphens replaced to empty strings: LEN($A2)-LEN(SUBSTITUTE($A2,"-","").
One more trick here - while we should remain the original string intact, we still MAY do anything with it for intermediate solutions! Thus, we replace the hyphen with #, and then search for # in temporary string.
All the above solutions are working, choose what you like / understand better. Hope that will also help in understanding array formulas, since for the same task there are 2 different approaches.
I updated the example file to include the last 2 examples + resulting megaformulas without intermediate steps, link is the same and located above. Good luck!
Here is a less than perfect solution:
Do a search & replace to get rid of any dashes that are not delimiters. For example, replace "mozilla-nss" with "mozillanss"
Put your values in Column A starting at A1
In B1, enter =LEFT(A1,FIND("-",A1)-1)
In C1, enter =SUBSTITUTE(A1,B1,"")
In D1, enter =SUBSTITUTE(LEFT(C1,FIND("-",C1,2)),"-","")
In E1, enter =SUBSTITUTE(SUBSTITUTE(C1,D1,""),"-","")
Fill Down the equations for all your values in Column A.
Edit: Added next line:
Replace "mozillanss" with mozilla-nss".
Your answers are in columns B,D, and E.

Resources