To extract words that begin with a specific character, you can use a formula based on six functions: TRIM, LEFT, SUBSTITUTE, MID, LEN, and REPT. This approach is useful if you need to extract things like a Twitter user name from a cell that contains other text.
The FIND function provides the starting point, and for total characters to extract, we just use LEN on the original text. This is a bit sloppy, but it avoids having to calculate the exact number of characters to extract. MID doesn't care if this number is bigger than the remaining characters, it simply extracts all text following "@".
Next, we "flood" the remaining text with space characters, by replacing any single space with 100 spaces using a combination of SUBSTITUTE and REPT:
This seems crazy, but the logic becomes clear below.
Next, to extract just the word we want (i.e. @word), we use LEFT to extract the first 100 characters from the left. This gets us "@word", plus many extra spaces. To visualize, the hyphens below represent spaces:
Now we just need to remove all extra spaces. For that, we use the TRIM function.
Note: 100 represents the longest word you expect to find that begins with the special character. Increase or decrease to suit your needs.
Got a better way to do this? Let me know in the comments below!
To extract text between parentheses, braces, brackets, etc. you can use a formula based on the MID function, with help from SEARCH function. In the example shown, the formula in C5 is: = MID ( B5 , SEARCH ( "(" , B5 ) + 1 , SEARCH (...
If you need to get the nth word in a text string (i.e. a sentence, phrase, or paragraph) you can so with a clever (and intimidating) formula that combines 5 Excel functions: TRIM, MID, SUBSTITUTE, REPT, and LEN. How this formula works At the core,...
If you need to extract the first word from some text you can use a formula that uses the FIND and LEFT functions. From the example, the formula looks like this: = LEFT ( B4 , FIND ( " " , B4 ) - 1 ) How this formula works FIND returns the...
The Excel SUBSTITUTE function replaces text in a given string by matching. For example =SUBSTITUTE("952-455-7865","-","") returns "9524557865"; the dash is stripped. SUBSTITUTE is case-sensitive and does not support wildcards.
Some formulas you see in Excel can be extraordinarily complex. But all complex formulas are built from simple steps. In this video, we built a more complex formula step by step.
Excel Formula Training
Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.