I wish to split a cell value
The cell value will be in the form of ###x###
Where # is a 0-9 number.
Also, the number of places can vary so it could be ###x#### or ####x####
This makes me unable to use LEFT or MID function
The common thing is the two numbers I want to extract separately are joined by 'x'
I tried using search function but could not find an answer.
How can I do this? With or without VBA? Thanks!
Let's assume your string is in the A1 field.
You may use either FIND or SEARCH function to find the position of the 'x' character.
=FIND("x", A1)
You get the first number by taking the characters from the left:
=LEFT(A1, FIND("x", A1) - 1)
You get the second number by taking the characters after until the end:
=MID(A1, FIND("x", A1)+1, 999)
(Of course, the parameter separator is according to your setting, so you may need to replace all the commas by semicolon or so.)
Related
I have a document in google sheets and the column consists of the name and version, like NLog.Config.4.3.0, NLog.Config.4.4.9 and so on.
See the image below for other examples.
I need to divide this into two columns - name and version, but I'm not familiar with regular expressions so close that I can get this info.
I can use excel and then import it to the Google doc, it doesn't matter for me how to do that.
enter image description here
You can try something like this:
Suppose you have your string in A1, then in B1 you can enter this:
=LEFT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")))
and in C1 this:
=RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1)
you may need to do some adjustments if there are cases without numbers as it will produce an error, for example you can round it with an Iferror like this:
=IFERROR(LEFT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))),A1)
Note: A1&"0123456789" is a 'trick' to avoid the search to return error, as the search is looking for all the numbers in the array; we just need the position of the first one, thus the MIN().
Supposing that your raw data were in A2:A, place this in B2:
=ArrayFormula(IFERROR(REGEXEXTRACT(A2:A,"(\D+)\.(.+)"),A2:A))
The regular expression reads "Extract any number of non-digits up to but not including a period as group one, and everything remaining into group two." (In other words, "As soon as you run into a digit after a period, start group two.")
The IFERROR clause means, "If this pattern can't be found, just return the original cell data."
Assuming your content is in column A (Google Sheets), try this arrayformula in any cell other than column A:
=arrayformula(iferror(split(REGEXREPLACE($A:$A,"(\.)(\d+.+$)",char(6655)&"$2"),char(6655)),))
There are two regex groups denoted in ():
(\.) and (\d+.+$).
The first group looks for a dot . - it's escaped using \. The second group looks for a number (0-9) \d, one or more occurrences + then ending with $ one or more + of any character ..
The replacement is char(6655) (wouldn't usually be found in your dataset), and the contents of group two $2.
Then the split function divides the text into two columns by the char(6655) character.
iferror returns nothing if nothing is split.
The arrayformula works down the sheet.
I found this formula which I can get the max value form a cell containing comma separated numbers. How can I get the min value using a similar approach?
=MATCH(1000,INDEX(FIND(","&ROW(INDIRECT("1:999"))&",",","&D2&","),0))
Cell content '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15'
You can try this:
=MIN(0+MID(SUBSTITUTE(A1, ",", REPT(" ",255)), 255*(ROW(INDIRECT("1:"&(1+LEN(A1)-LEN(SUBSTITUTE(A1,",","")))))-1)+1,255))
If one has FILTERXML:
=MIN(FILTERXML("<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>","//b"))
For the MAX, just replace the MIN with MAX.
I'd also go with FILTERXML. But if your string always follows this pattern it seems like the smallest number is always found on the left before the first comma which you could make perfect use of!
=--LEFT(A1,FIND(",",A1&",")-1)
Let's say I have the following value in a cell "test1_test2_test3_test4_test5". In another cell it could be "test1_test2_test3" or even "test 1_t est2".
What I would like is to have a 'general' function that I can specify to only give me back e.g. all characters before the first underscore, between the first en second underscore etc...and all the characters after the last underscore. And....if there isn't anything found, don't give back an error but just empty or nothing.
Thusfar I've googled a working format for when having a maximum of 2 underscores present (each different in formula):
For locating and displaying the characters before the first underscore: =LEFT(D32; SEARCH("";D32;1)-1)
For locating the characters after the first and before the second underscore: =MID(D32;SEARCH("";D32;1)+1;SEARCH("";D32;SEARCH("";D32;1)+1)-(SEARCH("";D32;1))-1)
For locating the characters after the second underscore (not limiting untill the next one is/is not present): =RIGHT(D32;LEN(D32)-SEARCH("";D32;SEARCH("_";D32;1)+1))
Ps: because my native (excel) language is Dutch, I've done my best to translate my working Excel functions to the English syntax.
With data in A1, in B1 enter:
=TRIM(MID(SUBSTITUTE($A1,"_",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
and copy across:
I suggest Text to Columns with underscore as the delimiter, count how many pieces result (COUNTA) and then pick to suit accordingly. Use IF to return blank ("") if say you want the text after the second underscore and the count is 1.
I need to replace a character, "-", with ":" in all of our product names. It needs to work for the entire column A, not just a single cell, AND there are multiple "-"'s in some of the products, but I just need the first in each product. For example, we have product Spuhr-SP-3016 and product AI-0497. I need to replace only the first - in the Spuhr one and the - in the AI one. And again, this will need to be for thousands of products, not just a single cell but a range (A2:A3000, or all of column A if range doesn't work). Is there a formula using either Replace or Substitute? All instructions I found demonstrate for one cell only instead of a range.
You can achieve this by using the FIND function in combination with LEFT and RIGHT
The FIND gets the first position of a "-" and you get the LEFT of that -1 so it ignores the "-". Then get the length, LEN, minus the same position from the first FIND without the -1 to get the rest of the string. In between both functions just add the ".".
=LEFT(A1,FIND("-",A1)-1)&"."&RIGHT(A1,LEN(A1)-FIND("-",A1))
I have a string in column A that is a mixture of letters and numbers. I want to split the string in half before the first number that shows up such that "abc123" becomes "abc" in column B and "123" in column C.
If there's any sort of pattern, e.g. always 3 letters.....or only 3 or 4 letters, for example then you can achieve more easily but for any number of letters (assuming that numbers always follow letters) you can use this formula in B2 (which is simpler than the suggested formula in topcat3's link, I think)
=LEFT(A2,MIN(FIND({1,2,3,4,5,6,7,8,9,0},A2&1234567890))-1)
and then this formula in C2
=REPLACE(A2,1,LEN(B2),"")
Note that this last formula returns the number part as a text value - if you want it to be numeric add +0 to end of formula (but you will lose any leading zeroes)
Just wanted to contribute a slight variation on Barry's formulas. Slightly easier to understand in my opinion but a little bit more difficult to use:
You can use this array formula to find the starting position + 1 of the first number:
{=MIN(IFERROR(FIND({1,2,3,4,5,6,7,8,9,0},A2),""))}
entered with ctrl+alt+enter to make it an array formula.
Then you can use that number to split the first part off of the string:
=LEFT(A2,B2-1)
And then you can use REPLACE() to get rid of the first part(the letters) off of the string.
=REPLACE(A2,1,LEN(C2),"")
You should accept Barry's answer and not this one because his is easier to use and more concise. But just wanted to add a variation in my quest to understand how Barry's formula worked.