close

Login to Excel-King.com

Please use the login boxes below to log in to my webpage. You need to login in i. e. to make sure you can post to the forums.

Log in here!

About the author

Image of Philipp Kowalski

Philipp Kowalski is a self-taught Excel-lover, project manager and blog-owner. Besides developing "beautiful" solutions in MS' premier spreadsheet tool, he loves his fiance, his cats and surfing the net. He is CEO and owner of Inservo IT, the company behind Excel-King. He's also available on Twitter and YouTube. If you like this website, please leave a comment. If you want to know more visit the forums or look into the about section of this website.

Today I would like to cover a functionality which is very handy for several purposes. With this function it is possible to extract a certain part of information from a value in a cell. The function is called LEFT.

Sounds simple, huh? In fact it is but it gets really interesting ,when you combine it with some other functions like we will do in our example below. By the way, LEFT has a twin, called RIGHT which does nearly with the one difference that it is starting from the other direction. It is only his stepbrother (or stepsister if you want to) because in a world where you write and read from left to right the function LEFT will start "from the beginning". The LEFT function has the following syntax:

=LEFT(text,num_chars)

This means that the first element we have to enter is the text from which we will extract our information. The number of characters (or chars) determines is the count that we will use starting with 1 as the first letter. Let's imagine we habe a list of international product IDs where the first 2 digits always describes the country, the product is manufactured in and the last 4 digits describe the article itself:

  A
1 Value
2 DE2589
3 US9204
4 UK6325
5 FR6321

We now want to extract both elements. LEFT and RIGHT are perfect functions for this purpose. For the first part (the country element) we use LEFT. The formula would be

=LEFT(A2,2)

That tells MSXL: Take the value in A2 and display the first two characrters. With the article ID we have to start from the right, so our formula looks like

=RIGHT(A2,4)

That tells MSXL: Take the value in A2 and display the last (because we read from left to right) 4 characters. The completed table looks like this:

  A B C
1 Value Country Product
2 DE2589 DE 2589
3 US9204 US 9204
4 UK6325 UK 6325
5 FR6321 FR 6321
Formulas in the table
Zelle Formel
B2 =LEFT(A2,2)
C2 =RIGHT(A2,4)
B3 =LEFT(A3,2)
C3 =RIGHT(A3,4)
B4 =LEFT(A4,2)
C4 =RIGHT(A4,4)
B5 =LEFT(A5,2)
C5 =RIGHT(A5,4)

Display Excel tables online >> Excel Jeanie HTML 4

Now let's go further with another a little bit more advanced example. Assuming we have a table with four names. By the way, this is the so called Queen table (labeled this way by me) because it shows the names of the members of the greatest rockband that ever existed on this planet: QUEEN

  A
1 Full Name
2 Freddy Mercury
3 Brian May
4 John Deacon
5 Roger Taylor

We now want to separate first name and surname out of the given values in cells A2 to A5. We will utilize - you guessed it - the LEFT function. But this function alone would not help us because as you can see from the table, the first names habe different lengths. But there is one thing the values in the cells have in common and that is their separator. Each first name and surname is sepaeated by a SPACE. We can search for this separator and this will help us determine the length. Therefore we will also use the SEARCH function, which has the following syntax

=SEARCH(find_text,within_text)

This function returns the position number of the text we have been looking for. It als has a third element - start_num - which is not covered in this example. So we let Excel search for the separator - the SPACE - in our text. The formula we will use for displaying the first name is

=LEFT(A2,SEARCH(" ",A2)-1)

In detail this means

=LEFT(A2,

Start extracting the text from the left position in cell A2

SEARCH(" ",A2)-1)

This is the second part in the left function and it is another function. The information in it says: search for the SPACE - " " - in cell A2 and return its position number. Also subtract 1 from this number because we only want to return the name and not the name + SPACE.

Now let's go to the surname. Unfortunately we have to follow another approach because similar to the LEFT function, the second element in the formula - syntax: =RIGHT(text,num_chars) - is the same. This means - as with the LEFT function - we cannot define a "starting point". Don't worry, we have a workaround for this because we will utilize another function ,called LEN (stands for length).

This function will return the total number of characters in a given value. So what we have to do here to find out the length of surname is subtract the position of the separator, again the SPACE, from the total length. Sounds complicated? For th name "Freddy Mercury" the total length is 14 characters and the position number of the SPACE is 7 so subtracting the latter from the first will lead is to the total number of charcters for the surname: 7.

The formula for displaying the surname is:

=RIGHT(A2,LEN(A2)-SEARCH(" ",A2))

In detail this tells MSXL to do the following

=RIGHT(A2,

Start extracting the text from the right position in cell A2.

LEN(A2)

Detemrine the total length of the information in cell A2

-SEARCH(" ",A2))

Determine the position of the SPACE in cell A2 and subtract it from the first element, length (LEN) resulting in the overall order to extract the 7 right characters. The overall table looks the following.

  A B C
1 Full Name First Name Surname
2 Freddy Mercury Freddy Mercury
3 Brian May Brian May
4 John Deacon John Deacon
5 Roger Taylor Roger Taylor
Formeln der Tabelle
Zelle Formel
B2 =LEFT(A2,SEARCH(" ",A2)-1)
C2 =RIGHT(A2,LEN(A2)-SEARCH(" ",A2))
B3 =LEFT(A3,SEARCH(" ",A3)-1)
C3 =RIGHT(A3,LEN(A3)-SEARCH(" ",A3))
B4 =LEFT(A4,SEARCH(" ",A4)-1)
C4 =RIGHT(A4,LEN(A4)-SEARCH(" ",A4))
B5 =LEFT(A5,SEARCH(" ",A5)-1)
C5 =RIGHT(A5,LEN(A5)-SEARCH(" ",A5))

Display Excel tables online >> Excel Jeanie HTML 4

This concludes our short overview of the LEFT and RIGHT function in MSXL. Any ideas or suggestions? What would you use this nice little function for? Tell us in the comments or share this post via social bookmarking.

discuss_it2.png

Discuss this blog post in the forums (click the blue button)


Administrator
Written on Saturday, 05 December 2009 00:00 by Administrator

Viewed 83 times so far.
Like this? Tweet it to your followers!

Rate this article

(0 votes)

Latest 'tweets' from Phil Kowalski

  • @jonstank hopefully you mean the tv series ;-) Link Monday, 08 March 2010 09:13
  • RT @happymakernowco Choose Happiness with Gratitude | Happy Maker Now http://bit.ly/cQgPki Link Sunday, 21 February 2010 05:12
  • RT @tweetmeme A Day Through the Eyes of a Blind Woman http://is.gd/7GTLq don't always take everything for granted!! Link Sunday, 21 February 2010 04:47
  • Spinning images http://is.gd/8ARak Link Wednesday, 17 February 2010 11:04
  • How does your Excel look like? http://is.gd/8vpph Link Tuesday, 16 February 2010 08:14

Add comment


Security code
Refresh

Sign up for updates

Receive the newest blog posts directly into your inbox!

Please note, that all fields are required.

First Name
Invalid Input
Family Name
Invalid Input
Email
Please enter your email address to receive our newsletter.

Please tick the check box to make sure, that you get the newsletter.

Get my VLOOKUP mini series as PDF for FREE as a little Thank You for signing up!

Sharing is caring

Facebook Twitter Digg Delicious Stumbleupon Google Bookmarks RSS Feed 

Tweet, Tweet...

Click the little blue friend to follow Phil on Twitter!

Advertisement

Create Excel dashboards quickly with Plug-N-Play reports.