Need excel formula to extract a single or double digit number preceding a character or symbol - string

Here's the case I have a column with a number of text strings. Each string contains either a single or double-digit number followed by either an "x" or the words " set" or " rounds." I'm trying to extract the numbers preceding the "x" or the words. Here's an example:
string
Desired Outcome
jump 3x10
3
push 10x3
10
pull 3 sets 10 times
3
pull 3 rounds 8 times
3
push 10 times 3 sets
3
I've tried FIND, SEARCH, {1,2,3,4, 5, 6,7, 8, 9} only to over-complicate this. There has to be a simple way to locate these combinations (##&"x", "## sets" or ""## rounds") and extract the related numbers.

Assume "String" data housed in Column A1:A6 with header.
In "Outcome" B2, formula copied down :
=LOOKUP(9^9,0+RIGHT(LEFT(A2,MIN(SEARCH({"x"," sets"," rounds"},A2&"x sets rounds"))-1),ROW(A$1:A$250)))

Related

Excel formula to extract a number preceding an x not working

I'm using the following formula to extract the number preceding an "x" from a string (e.g. ##x## where # equals a number 0-9) but with I have other words in the string that have an "x" in them, the formula doesn't work.
Here's the formula:
=IF(ISBLANK(A154),"",IFERROR(IF(VALUE(MID(A154,MIN(FIND({"1","2","3","4","5","6","7","8","9","0"},A154 & "(1,2,3,4,5,6,7,8,9,0")),FIND(INDEX(SET_TERMS,MATCH(1,COUNTIF(A154,"*"&$R$2:$R$5&"*"),0)),A154,1)-MIN(FIND({"1","2","3","4","5","6","7","8","9","0"},A154 & "(1,2,3,4,5,6,7,8,9,0"))))<=1,"",TRIM(MID(A154,MIN(FIND({"1","2","3","4","5","6","7","8","9","0"},A154 & "(1,2,3,4,5,6,7,8,9,0")),FIND(INDEX(SET_TERMS,MATCH(1,COUNTIF(A154,"*"&$R$2:$R$5&"*"),0)),A154,1)-MIN(FIND({"1","2","3","4","5","6","7","8","9","0"},A154 & "(1,2,3,4,5,6,7,8,9,0")))&" sets")),""))
Notes: SET_TERMS ($R$2:$R$5) is a list: rounds, set, sets, x.
Here are examples where the formula works fine:
Skater jumps 3x5 each side RESULT 3 sets
Russian Twist 3x30 seconds RESULT 3 sets
Push-ups 3x max RESULT 3 sets
Y holds 3x30 seconds RESULT 3 sets
Now, here are two examples of the strings that return a blank because Flexion and Extension have "x" in them:
Neck Flexion 3x20 seconds RESULT Blank
Neck Extension 3x20 seconds Result Blank
Any ideas on how to fix this?
Thanks
You just need to be more specific in what you are looking for.
For example, the following will return the digit prior to the x:
=MID(A1,MIN(FIND({0;1;2;3;4;5;6;7;8;9}&"x",A1&"0x1x2x3x4x5x6x7x8x9x")),1)
If you have Windows Excel 2013+ or O365, and you need to deal with multiple digit numbers, the following will extract space-separated "nodes" that have the pattern of ddx, where dd can be any number (including decimals). You can then use string functions to extract just the number.
=FILTERXML("<t><s>" & SUBSTITUTE(A1," ","</s><s>") & "</s></t>","//s[boolean(number(substring-before(.,'x')))]")

Converting number strings to Values in Excel

After scraping a website I ended up with values with dashes in the data like 7-6, 12-5, 3-12. I was able to separate the data into to their own columns making the previous examples being 7, 6 , 12,5 3,12, but the data has turned from values that you can add and subtract to something like a string. Is there a way to make the strings into values.
0 15
1 2
5 6
4 8
3 2
2 1
If i go through each cell and double click the strings it converts to values, but I cant do that to 55000 cells.
you can convert a text string that represents a number to number format using the Value() formula
Example:
B1 = Value(A1))
if A1 = 15 in text format
You can select the whole columns and convert to number. Go to menu Data > Convert and then, follow the wizard.

How to build complex value from three variables?

I have an Excel spreadsheet with over 2000 entries:
Field B1: CustomerID as 000012345
Field B2: CustomerID as 0000432
Field C1: CustomerCountry as DE
Field C2: CustomerCountry as IT
I need to build codes 13 digits long including "CustomerCountry" + "CustomerID" without leading 0 + random number (can be 6 digits, more or less, depends in length of CustomerID).
The results should be like this: D1 Code as DE12345967895 or D2 Code as IT43274837401
How to do it with Excel functions?
UPDATED:
I tried this one. My big problem is to say that random number should be long enough to get 13 characters in all. Sometimes CustomerID is just 3 or 4 digits long, and concatenation of three variables can be just 10 or 9 characters. But codes have to be always 13 characters long.
Use & to concatenate strings.
Use VALUE(CustomerID) to trim the leading zeroes from the ID
Use RAND() to add a random number between 0 and 1 or RANDBETWEEN(x,y) to create one between x and y.
Combine the above and there you are!
If you always want 13 digits you can use LEFT(INT(RAND()*10^13);(13-LEN(CustomerCountry)-LEN(VALUE(CustomerID)))) for the random number to ALWAYS be the right length.
total formula
= CustomerCountry
& VALUE(CustomerID)
& LEFT(INT(RAND()*10^13);(13-LEN(CustomerCountry)-LEN(VALUE(CustomerID))))
=C1 & TEXT(B1,"0") & RIGHT(TEXT(RANDBETWEEN(0,99999999999),"00000000000"),11 - LEN(TEXT(B1,"0")))
that should do it
I don’t understand what is where and OP has accepted answer so have not bothered testing:
=LEFT(RIGHT(C1,2)&VALUE(MID(B1,15,13))&RANDBETWEEN(10^9,10^10),13)
(but I might revert to this if no one else picks the flaws in it first!)

=IF(ISNUMBER(SEARCH.... the difference between 1 and 11

I am trying to convert a single column of numbers in excel to multiple depending on the content.
e.g. Table 1 contains 1 column that contains 1 or more numbers between 1 and 11 separated with a comma. Table 2 should contain 11 columns with a 1 or a 0 depending on the numbers found in Table 1.
I am using the following formula at present:
=IF(ISNUMBER(SEARCH("1",A2)),1,0)
The next column contains the following:
=IF(ISNUMBER(SEARCH("2",A2)),1,0)
All the way to 11
=IF(ISNUMBER(SEARCH("11",A2)),1,0)
The problem with this however is that the code for finding references to 1 also find the references to 11. Is it possible to write a formula that can tell the difference so that if I have the following in Table 1:
2, 5, 11
It doesn't put a 1 in column 1 of Table 2?
Thanks.
Use, for list with just comma:
=IF(ISNUMBER(SEARCH(",1,", ","&A2&",")),1,0)
If list is separated with , (comma+space):
=IF(ISNUMBER(SEARCH(", 1,", ", "&A2&",")),1,0)
A version of LS_dev's answer that will cope with 0...n spaces before or after each comma is:
=IF(ISNUMBER(SEARCH(", 1 ,",", "&TRIM(SUBSTITUTE(A2,","," , "))&" ,")),1,0)
The SUBSTITUTE makes sure there's always at least one space before and after each comma and the TRIM replaces multiple spaces with one space, so the result of the TRIM function will have exactly one space before and after each comma.
How about using the SUBSTITUTE function to change all "11" to Roman numeral "XI" prior to doing your search:
=IF(ISNUMBER(SEARCH("1",SUBSTITUTE(A2, "11", "XI"))),1,0)
If you want to eliminate "11" case, but this is all based on hardcoded values, there should be a smarter solution.
=IF(ISNUMBER(SEARCH(AND("1",NOT("11")),A2)),1,0)

how to extract 10 digit number from column excel

I have column which consists of text including 13 digit number. How Can I keep 10 digit number and delete all other text?
Please help me I am new to excel..
thanks in advance
Edited:
Cell Format
[6/11/2013 3:26:37 PM] 1234503776599, ksdfl 038ddf63Ksdf)
[6/12/2013 3:26:37 PM] 0234503664599, ksdfadssdfl 038ddf6dfsd3Ksdf)
[6/13/2013 3:26:37 PM] 7234503666099, 45sdsdfadssdfl 03845ddf6dfsd3Ksdf)
Here, In second column I want to keep 13 digit and delete all text after that 13 digit.
Is the number always at the beginning of the cell? If so you can use =LEFT(cell_ref, 10) to extract the first 10 characters, which in this case are numbers and will be treated as such by the spreadsheet.
I'm guessing you will need something like this
=MID(A1,32,FIND(",",A1,32) -32)
MID will get text from the middle of a string
FIND will get the location of the first comma
Thinking that the 13 digit number is in the middle of the string, with 9 spaces to the left and a comma to the right we can use the following formula in a separate cell:
=MID(A1,LEN(LEFT(A1,FIND("]",A1)+1))+9,13)
The LEN function determines the length of the part up to and including ] (big bracket). Then the number 9 is added to include nine spaces. Then the number 13 is the length of the 13 digit number. All these are used as parameters for the MID function.
After you get the result just drag down using the autofill handle to get the mid 13 digit number for all the rows.
=LOOKUP(10^11,MID(A1,ROW(INDIRECT("1:"&LEN(A1)-9)),11)+0)
This works for me.
To extract 6 continuous numeric digits, use the below code:
=LOOKUP(10^6,MID(A1,ROW(INDIRECT("1:"&LEN(A1)-5)),6)+0)
Replace 6 in the above code with the number of digits that are required to be extracted.

Resources