Extract word which containing specific text in Excel
Sometimes, you may want to extract the word from a cell that contains a specific character or text, such as following screenshot shown, to extract all words that containing the “=” character. How could you solve this task in Excel?
Extract word which containing a specific character or text
To solve this problem, you should create a formula which combines the TRIM, MID, SUBSTITUTE, REPT, MAX and FIND functions. The generic syntax is:
- string: The text string or cell value that you want to extract word inside.
- char: The character or text that you want to extract word contains.
1. Please enter or copy the following formula into a blank cell where you want to get the result:
2. Then, drag and copy the formula to the cells that you want to use, and you will get the following result:
Explanation of the formula:
- SUBSTITUTE(A2," ",REPT(" ",99)): This SUBSTITUTE function will replace each single space with 99 spaces which are returned by the REPT function, and get a new text string with multiple spaces between each word. The number 99 is just an arbitrary number that represents the longest word you need to extract.
- FIND("=",SUBSTITUTE(A2," ",REPT(" ",99)))-50: This FIND function is used to find the position of the first specific character (in this case, “=”) inside the new text string returned by the SUBSTITUTE function.
- MAX(): If the substring appears in the front of the text string, the FIND function will get a negative number, and this MAX function is used to reset the negative value to 1.
- MID(SUBSTITUTE(A2," ",REPT(" ",99)),MAX(1,FIND("=",SUBSTITUTE(A2," ",REPT(" ",99)))-50),99): This MID function is used to extract 99 characters from the text string which is returned by the SUBSTITUTE function at a specific position that returned by the FIND function.
- TRIM(): This TRIM function removes all extra spaces from text string returned by the MID function.
1. In the above formula, you can change the “=” character to any other character or text you need.
2. If there are multiple words which contain the specific character, only the first word will be extracted.
Relative functions used:
- The REPT function is used to repeat the characters a specified number of times.
- The SUBSTITUTE function replaces text or characters within a text string with another text or characters.
- The TRIM function removes all extra spaces from text string and only keeps single spaces between words.
- The MID function returns the specific characters from the middle of text string.
- The MAX function returns the largest numeric value in a range of values.
- Extract Word Beginning With A Specific Character In Excel
- For example, you may need to extract the word which begins with a specific character “=” for each cell as below screenshot shown, how could you solve this task quickly and easily in Excel?
- Extract Text Between Parentheses From Text String
- If there is part of the text surrounded with the parentheses within the text string, now, you need to extract all the text strings between the parentheses as following screenshot shown. How could you solve this task in Excel quickly and easily?
- Extract Last Line Of Text From A Multi-Line Cell
- To extract the last line of text from a text string which is separated by line breaks, normally, there is no direct way for you to solve this. This article, I will introduce a formula to deal with this task in Excel.