Excel: How to extract text strings from a formula? - excel

I want to split text strings from the below formula in a cell that generates a numeric value.
=RTD($A$1;;"aaa#bbb//ccc////ddd")
Using the mid & search funktion to split certain parts such as =MID(A23; SEARCH("////";A23)+4; 3) only works if text is stored in cells, but not on a formula in the cell.
How to extract strings from a formula?

As per the comment section you can use FORMULATEXT(). If you have TEXTAFTER() available, try:
=LEFT(TEXTAFTER(FORMULATEXT(A1),"////"),3)

If you don't want to use the formulatext function, you can use the find and replace. Replace for exampel the "=" with "#="
Then you can extract what ever you want with the mid function.
When you are done replace "#=" with "="

Related

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

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.

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!

Using Indirect function in CountIf formula to count the number of times the text string occurs in a column

Hi and thank you in advance for your help.
I am trying to count the number of times a text string, for example "UML" occurs within a column. The column may contain the text by itself or it may contain the text(UML) in a list with other text(UML,SAS,Excel). I need to be able to count it even if it's within a list. I understand using two * on each side of the text string will work if I write it out but I don't want to write it over and over again.
I am open to alternatives other than countif formula but if there is a way to do it with countif would you please share both.
Thanks again for your help!
If column F contains your lookup value, and it's contained in square brackets, then building on your formula I'd use:
=COUNTIF($A$1:$A$4247,SUBSTITUTE(SUBSTITUTE("*" & F2 & "*","[",""),"]",""))
We substitute the square brackets for nothing, to remove them on the fly from the lookup value. Then we search the strings, basically for *UML*. And this formula is draggable downable (F2 will move with you). Is this what you need?
Just to put my two cents in:
The formula to count column A on what is entered in F2 is:
=Countif(A:A,"*" & F2 & "*")

Adding numbers enclosed in characters

I am trying to add numbers in excel which contain characters.
For example, I want to add
rs30/-
rs40/-
rs45/-
I want result as rs115/-
I tried
=SUM(IF(ISNUMBER(--A1:A3),--A1:A3))
but that gives zero.
You can use MID to extract the number text from the character string, then VALUE to convert that text to an actual numerical value, then add those using SUM, then use & to concatenate with the characters you want before and after the result.
Example:
="rs" & SUM(VALUE(MID(A1:A3,3,LEN(A1:A3)-4))) & "/-"
entered as an array formula using Ctrl Shift Enter.
You might prefer to strip out rs and /- (with Find & Select), then format as:
"rs"0"/-"

Resources