Mohamed Nada
  • Home
  • Blog
  • Resources
    • Pivot Tables e-Book
    • Excel Cheat Sheets
  • About Me
  • Contact
x
Get this eBook for FREE and learn all about Pivot Tables in just one hour!
Picture
Download free ebook

5 Basic Text Functions in Excel to Extract, Separate, Join and Clean text

10/22/2017

Comments

 
​​Most of the times, we use Excel to crunch numbers, but what a lot of people don’t know is that Excel is a very effective tool to crunch text as well.
​
We can use Excel to clean text fields, extract specific information from text fields, or join text fields together.
Let’s have a look at the example below where have some text fields extracted from a database (columns A to E) and we would like to do some manipulations over them in the green columns F to J.

You can download the sample workbook from here.
Picture
​In the first column, we have the State-Zip codes. We know that the state is the first 2 letters from the left, and the Zip code is the 5 numbers from the right. Let’s separate those to have the state in column F and the Zip code in column G.

To do this, we use the functions LEFT and RIGHT.
​
In cell F2, we type =LEFT and open a bracket. Then we will find 2 arguments. The first one is the text, which in this case is the State-Zip cell, and then the number of characters, which is 2 since we need only the first 2 characters. We then drag the formula along the column.
Picture
For the Zip code, we go to cell G2, and type =RIGHT then open a bracket, and again the same 2 arguments are the text and number of characters. In this case the number of characters will be 5 since we need the 5 characters from the right. We then drag the formula along.
Picture
Next, we see that in columns B and C we have first names and last names respectively. Now we need to join these 2 names together to form the Full Name in column H. There are 2 ways to do this.
​

The first one is using the CONCATENATE function. We go to cell H2, type CONCATENATE, open a bracket, and type as many texts as you need to join, separated by a comma. ​
Picture
When we concatenate cells B2 and C2, we find that the result in H2 actually joins the 2 names but without any spaces in between. We can include the space as an argument in the concatenate function by typing space between speech marks (i.e. “ “). The final formula and result will look like this:
Picture
The second way to join text strings is using the Ampersand sign "&" (which you can type using Shift + 7 on your keyboard).

To do this, we don’t have to use any functions. We just type the = sign, choose the text and then join it using the & sign with another text and so on. The formula will look like this:
Picture
Note that we joined the space “ “ with a & sign as well.

Now let’s extract the product model from the product number in column D. We know that the model is the 2 letters in the middle of the product number (i.e. in 475AR9096, the model is AR).

To do this, we use the MID function. We go to column I, type MID and open a bracket. We see that the MID function has 3 arguments:
  1. The first one is the text: this is the text string which is the product number.
  2. The second argument is the start_num: this is the starting point of the text we need to extract. We start from the left side, and count the number of characters until we find the text to be extracted. In our example, we counted 3 numbers and then the model is the 4th character from the left, so we type 4.
  3. The third argument is the num_chars: this is the number of characters that we need to extract. So after I counted 4 characters from the left in the previous argument, how many characters to do we need to extract? In this case the Model is only 2 characters, so we just type 2.
 
The final output will look like this:
Picture
Finally, we would like to clean the Web Site column because it includes a lot of spaces either before or after the text strings (it’s obvious in some fields, but not very obvious in other fields where the space comes at the end of the text. You can examine this further in the worksheet yourself).
​
To clean this, we use the TRIM function which basically removes any additional spaces before or after any text. To use it, we just type TRIM and choose the text we need to clean. It’s very straight forward.
Picture
As a bonus step, we can precede the result with a “www.” and finish it with a “.com” for a better display of the website using CONCATENATE function or the & sign.
Picture
​Now we have seen how can you use Excel to extract, join, separate or clean text strings. Now go ahead and try it on your own data. Feel free to post your questions in the comments field below.
 
Happy Excelling!
Comments
© 2017 Mohamed Nada. All Rights Reserved.
  • Home
  • Blog
  • Resources
    • Pivot Tables e-Book
    • Excel Cheat Sheets
  • About Me
  • Contact