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

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)

Related

How to extract text from a string between where there are multiple entires that meet the criteria and return all values

This is an exmaple of the string, and it can be longer
1160752 Meranji Oil Sats -Mt(MA) (000600007056 0001), PE:Toolachee Gas Sats -Mt(MA) (000600007070 0003)GL: Contract Services (510000), COT: Network (N), CO: OM-A00009.0723,Oil Sats -Mt(MA) (000600007053 0003)
The result needs to be column1 600007056 column2 600007070 column3 600007053
I am working in Spotfire and creating calclated columns through transformations as I need the columns to join to other data sets
I have tried the below, but it is only picking up the 1st 600.. number not the others, and there can be an undefined amount of those.
Account is the column with the string
Mid([Account],
Find("(000",[Account]) + Len("(000"),
Find("0001)",[Account]) - Find("(000",[Account]) - Len("(000"))
Thank you!
Assuming my guess is correct, and the pattern to look for is:
9 numbers, starting with 6, preceded by 1 opening parenthesis and 3 zeros, followed by a space, 4 numbers and a closing parenthesis
you can grab individual occurrences by:
column1: RXExtract([Amount],'(?<=\\(000)6\\d{8}(?=\\s\\d{4}\\))',1)
column2: RXExtract([Amount],'(?<=\\(000)6\\d{8}(?=\\s\\d{4}\\))',2)
etc.
The tricky bit is to find how many columns to define, as you say there can be many. One way to know would be to first calculate a max number of occurrences like this:
maxn: Max((Len([Amount]) - Len(RXReplace([Amount],'(?<=\\(000)6\\d{8}(?=\\s\\d{4}\\))','','g'))) / 9)
still assuming the number of digits in each column to extract is 9. This compares the length of the original [Amount] to the one with the extracted patterns replaced by an empty string, divided by 9.
Then you know you can define up to maxn columns, the extra ones for the rows with fewer instances will be empty.
Note that Spotfire always wants two back-slash for escaping (I had to add more to the editor to make it render correctly, I hope I have not missed any).

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

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)))

IFERROR with 3 values

I have a VLOOKUP for postcodes and currently it works when searching for both 3 and 4 character postcodes
e.g.
TW13 - Feltham
UB3 - Uxbridge
=IFERROR(VLOOKUP(LEFT(F2,4)&"*",Postcodes!A:C,3,FALSE),VLOOKUP(LEFT(F2,3)&"*",Postcodes!A:C,3,FALSE))
But I forgot that there are 2 character postcodes and both VLOOKUP and IFERROR only allow two checks to be made.
So where should I be looking to first check for 4 characters, then 3 characters or worst case 2 characters? If it helps all my postcodes are in the correct format with the space e.g. TW13 9XX, UB3 4XJ, W3 4EE.
Just nest in another IFERROR() in the value_if_error clause of the first:
=
IFERROR(VLOOKUP(LEFT(F2,4)&"*",Postcodes!A:C,3,FALSE),
IFERROR(VLOOKUP(LEFT(F2,3)&"*",Postcodes!A:C,3,FALSE),
VLOOKUP(LEFT(F2,2)&"*",Postcodes!A:C,3,FALSE)))
How about just extracting the part prior to the breaking space in postcodes
=IFERROR(VLOOKUP(LEFT(F2,FIND(" ",F2)-1)&"*",Postcodes!A:C,3,FALSE),"")

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!)

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