How to get string after 3 slash in excel - excel

I'm having difficulties to find a way of getting the string before the last slash in excel 2007 formula.
https://www.example.com/text13611283/url_complement
The string I need is this: text13611283

There are multiple ways to do this task based on input value
Case 1: you can Delimit the column by using menu "DATA/Text to Columns"
Case 2: Assuming your text is in A2 Cell the formula in B2 will be "=LEFT(MID(A2,FIND("/",A2,10)+1,100),FIND("/",MID(A2,FIND("/",A2,10)+1,100),1)-1)"

The String Between the Last Two Occurrences of a Slash (/) in Cell A1
Formula
=MID(A1,FIND("#",SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))-1))+1,FIND("#",SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))))-FIND("#",SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))-1))-1)
How?
How Formulas
=LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))
=SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/","")))
=FIND("#",SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))))
=LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))-1
=SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))-1)
=FIND("#",SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))-1))
=MID(A1,FIND("#",SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))-1))+1,FIND("#",SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))))-FIND("#",SUBSTITUTE(A1,"/","#",LEN(A1)-LEN(SUBSTITUTE(A1,"/",""))-1))-1)

=INDEX(TRIM(MID(SUBSTITUTE(A1,"/",REPT(" ",99)),IF(ROW(INDEX($A:$A,1):INDEX($A:$A,255))=1,1,(ROW(INDEX($A:$A,1):INDEX($A:$A,255))-1)*99),99)),4)
Replace each / with 99 spaces
Using MID, create an array of each 99-space separated element in the string
=IF(ROW(INDEX($A:$A,1):INDEX($A:$A,255))=1,1,(ROW(INDEX($A:$A,1):INDEX($A:$A,255))-1)*99) creates an array to be used for the start argument of the MID function. It returns an array of {1,99,198,297,...}
TRIM to get rid of the extra spaces
INDEX to extract the correct element. In this case, it would be 4.

Related

How do I remove a specific value from a string of comma separated values?

I have two columns. Column A with a single value and Column B with a string of comma-separated values.
I want to find the value in Column A in the string of values in Column B and remove it. Leaving the remainder of the values separated by the commas.
For example:
The SUBSTITUTE formula ive been playing with is =SUBSTITUTE(B2,A2," ")
One issue that I'm running into is some of the values have the "/" character in them which I wish to keep.
Example:
Column A
FC0201F1I
Column B
FC0201F1I,FC0201F1I/FC0201F2I,FC0201F2I
SUBSTITUTE output ruins the Value:
, /FC0201F2I,FC0201F2I
The output I'm looking for:
FC0201F1I/FC0201F2I,FC0201F2I
Any Excel Formula combination or VBA Code to help me in this mystery would be greatly appreciated. I feel the solution is so simple and staring at me in the face but I am unable to see it.
Thank you for all your help!
Add commas to the beginning and end to both strings inside the SUBSTITUTE then use spaces and trim to remove the , if they are added to the front or back and not replaced:
=SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(","&B2&",",","&A2&",",""),","," "))," ",",")
Alternatively, this is possible through some xpath in FILTERXML():
Formula in C1:
=TEXTJOIN(",",,FILTERXML("<t>"&A1&"<s>"&SUBSTITUTE(B1,",","</s><s>")&"</s></t>","//s[.!=../text()]"))
Do 2 substitutions, 1 for the search term followed by a column and 1 for the search term preceded by a comma.
=SUBSTITUTE(SUBSTITUTE(B2,","&A2, ""), B2&",","")

match the number from comma separated value and count

I have a comma separated value in A2 and same numbers in different cells B1, C1, D1.... I want to match them from comma separated value and find out the count in B2, C2, D2. Please see the image attached you will get the context.
Can we achieve this by formula or macro in excel?
Tried formula:
=LEN(TRIM($A$2))-LEN(SUBSTITUTE(TRIM($A$2),C1,","""))
Also, I have two data sets where I will be using this formula to find out the count of number from comma-separated value and based on count I want the repeated ones to come in a different cell please refer the image for better understanding.
Probably not the best solution but get the job done. Please note it is case-sensitive and please make sure to press Ctrl+Shift+Enter upon finishing this formula.
{=SUM(--(EXACT("!"&TRIM(MID(SUBSTITUTE($A2,",",REPT(" ",100)),(ROW(INDIRECT("1:"&LEN($A2)))-1)*100+1,100)),"!"&B1)))}
You can replace ! in the above formula with a unique symbol that will never appear in the text string to be safer.
The logic is to SUBSTITUTE the comma , with and long string of blanks, then use MID to find each value in the text string and return the result as an array, then use EXACT to match each value in the array with the look up value and return a new array of TRUE and FALSE, then SUM up all TRUE which will give the count of the look up value.
UPDATE #2
As requested by OP, here is one way of solving the second query which is to match the same value with the same occurrence from two text strings separated by comma ,.
The formula in Cell C2 is from the original solution which is used to find the occurrence of a given value in a text string;
The formula for Range C6:K6 is an array formula as shown below. I used a helper row to layout the matching values, and excluding the one that has 0 count for both data set;
{=IFERROR(INDEX($C$1:$K$1,,AGGREGATE(15,7,COLUMN(INDIRECT("1:"&COLUMNS($C$1:$K$1)))/($C$2:$K$2=$C$3:$K$3)/($C$2:$K$2>0),COLUMN()-2))&",","")}
The formula in Cell L8 is concatenating all values from Range C6:K6 and remove the last comma , from the final text string:
=LEFT(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6),LEN(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6))-1)
The following worked for me, give it a try:
Formula in B2:
=(LEN(","&SUBSTITUTE($A$2,",",",,")&",")-LEN(SUBSTITUTE(","&SUBSTITUTE($A$2,",",",,")&",",","&B$1&",","")))/LEN(","&B$1&",")
Drag right...
A simpler way of doing it is to simply calculate the difference in the length of the string minus the length of the string when replacing the value searched by nothing and dividing by the length of the string searched
The formula would be:
=(LEN($A$1)+1-LEN(SUBSTITUTE($A$1&",",B1&",","")))/LEN(B1&",")
There is a much simpler solution:
=COUNTIF(SPLIT($A$2, ","), B1)

Extract substring from this string inside Excel cell

I have this Excel cell A2 with the contents USD.EUR[IDEALPRO,CASH,EUR].
I would like to extract the substring EUR from the last part of the string using an Excel formula. The nearest formula I came out with is =RIGHT(A2,4). However, it returns EUR].
What formula can be used to extract the substring?
I am using MS Excel 2013.
If the string that you are searching is only 3 bytes in length, then your simple formula works. But what if it changes? Try the below,
=MID(SUBSTITUTE(F2,",","#",LEN(F2)-LEN(SUBSTITUTE(F2,",",""))),FIND("#",SUBSTITUTE(F2,",","#",LEN(F2)-LEN(SUBSTITUTE(F2,",",""))))+1,FIND("]",SUBSTITUTE(F2,",","#",LEN(F2)-LEN(SUBSTITUTE(F2,",",""))))-FIND("#",SUBSTITUTE(F2,",","#",LEN(F2)-LEN(SUBSTITUTE(F2,",",""))))-1)
Where F2 is your string. This formula unstrings the string between the last delimiter "," and "]". This is too complicated but it might help you.
I will answer my own question. It has been tested to work.
=SUBSTITUTE(RIGHT(A2,4),"]","")
RIGHT(A2,4) returns EUR]. Afterwards, use SUBSTITUTE to remove ].
You can use a combination of MID and REVERSETEXT functions.
Formula
=REVERSETEXT(MID(REVERSETEXT(A1), 2, 3))
Otherwise, if the length is unknown for the part which you want to retrieve. Then use FIND function to find the comma before that particular word.
=REVERSETEXT(MID(REVERSETEXT(A3), 2, FIND(",", REVERSETEXT(A3)) - 2))

How to extract parsed data from once cell to another

Given a spreadsheet cell containing a string that consists of a hyphenated series of character segments, I need to extract the last segment.
For example, consider column A containing data strings like XX-XXX-X-XX-XX-G10, where X denotes any character. What formula would I need to place in column B to get G10 as a result?
A B
1 XX-XXX-X-XX-XX-G10 G10
I'm looking for a formula that could work in in Libre Office Calc, Open Office Calc, MS Excel, or Google Sheets.
Another possibility in LO Calc is to use the general purpose regular expression macro shown here: https://superuser.com/a/1072196/541756. Then the cell formula would be similar to JPV's answer:
=REFIND(A1,"([^-]+$)")
If you are using google sheets, regexextract would be possible too:
=REGEXEXTRACT(A1, "[^-]+$")
In LibreOffice Calc and OpenOffice Calc, you can use a regular expression to determine the position of the text after the last - character:
=SEARCH("-[:alnum:]+$";A1)
will return 15 if A1 contains XX-XXX-X-XX-XX-G10.
Now, you can use this value to get the text "behind" that position, using the RIGHT() function:
=RIGHT(A1;LEN(A1)-SEARCH("-[:alnum:]+$";A1))
Split up on multiple lines:
=RIGHT( ' return text beginning from the right...
A1; ' of cell A1 ...
LEN(A1) ' start at lenght(A1) = 18
- ' minus ...
SEARCH( ' position ...
"-[:alnum:]+$" ' of last "-" ...
;A1 ' in cell A1 = 15 ==> last three characters
)
)
It appears that you want the characters that appear at the end of a string, to the right of the last instance of a hyphen character, "-".
This formula, adapted from here, works in Excel, *Calc & Google Sheets:
=TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",LEN(A1))),LEN(A1)))
Explanation:
SUBSTITUTE(A1,"-",new_string) will find each hyphen ("-") in the original string from cell A1 and replace it with a new_string.
REPT(" ",LEN(A1)) is a string of repeated space characters (" "), the same length as the original string in cell A1.
TRIM(RIGHT(string,count)) will get the right-most count characters, and trim off leading and trailing spaces. Since the string was previously padded out by replacing hyphens with spaces, and count is the same LEN(A1) used for that padding, the last count characters consists of a bunch of spaces followed by whatever followed the last hyphen!
In Google Sheets, an alternative approach is to use the SPLIT function to break the value from column A into an array, then select the last element. (Excel-VBA has a split() function, so you could make this work in Excel by writing VBA code to provide it as a custom function.)
=INDEX(SPLIT(A1,"-"),0,COUNTA(SPLIT(A1,"-")))
I found simply solution:
=RIGHT(A1;3)
that gives me G10 as the result too! It works because COL A always have 3 chars at the end!

MS Excel: remove number of characters after a specific character in a string

I have a column with values like
WI60P-14E64F5167E6-01138
or
WI60-34D03E185267-01051
etc....
i need to find the first occurrence of - till the second occurrence of - and remove the resulting character.
I am using this function =MID(A1,FIND("-",A1),13) which returns me -34D03E185267 or -14E64F5167E6 from the above strings.
But I want the output like WI60P-01138 or WI60-01051
Can anyone help me?
Assuming that the length of text between the two hyphens never varies, you can use your existing function, along with SUBSTITUTE to get the desired string, like so:
=SUBSTITUTE(A1,MID(A1,FIND("-",A1),13),"")
Alternately, you can use FIND to get the hyphen positions and again use SUBSTITUTE to get the replaced string, like so:
=SUBSTITUTE(A1,MID(A1,FIND("-",A1),FIND("-",A1,FIND("-",A1)+1)-FIND("-",A1)),"")
Notice that one of the FIND expressions takes 3 parameters - by passing FIND("-",A1) + 1 as the third parameter, we get the second occurence of '-' within the cell.
This will work for any position of the two hyphens:
=CONCATENATE(MID(A1;FIND("-";A1)+1;FIND("-";A1;FIND("-";A1)+1)-FIND("-";A1)-1))
Solution using multiple cells as support (with dynamic length of the string):
Put this in cell B1 to obtain the first part of the code:
=MID(A1,1,FIND("-",A1)-1)
Put this in cell C1 to obtain the last part of the code:
=MID(A1,FIND("-",A1)+1,LEN(A1))
Put this in cell D1 to concatenate both and get your result:
=concat(B1,C1)
Solution in a single cell (with dynamic length of the string)
Put this in cell B1 to get the same result as above :
=concat(MID(A1,1,FIND("-",A1)-1),MID(MID(A1,FIND("-",A1)+1,LEN(A1)),FIND("-",MID(A1,FIND("-",A1)+1,LEN(A1))),LEN(MID(A1,FIND("-",A1)+1,LEN(A1)))))

Resources