Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Returning the Left-most Characters.

Returning the Left-most Characters

by Allen Wyatt
(last updated February 15, 2014)

8

Sometimes you may need to create a worksheet formula that examines the left-most characters in a different cell. To allow for this need, Excel provides the LEFT worksheet function. You use it by specifying the cell or value to use, along with the number of character to return. For instance, the following formula returns the three left-most characters in cell A7:

=LEFT(A7,3)

If the value in A7 is not text, then LEFT still treats it as if it is. Thus, if A7 contains 12345, then the above formula returns the text value 123.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2488) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Returning the Left-most Characters.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Using AutoFiltering

Excel's AutoFilter tool is a great way to make a long list of items much more manageable. This tip explains how to set up an ...

Discover More

Stopping Date Parsing when Opening a CSV File

Excel tries to make sense out of any data that you import from a non-Excel file. Sometimes this can have unwanted results. ...

Discover More

Ensuring Unique Values in a Column

If you want to make sure that only unique values are entered in a particular column, you can use the data validation ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

Making PROPER Skip Certain Words

The PROPER worksheet function is used to change the case of text so that only the first letter of each word is uppercase. ...

Discover More

Cleaning Text

You can use the CLEAN worksheet function to remove any non-printable characters from a cell. This can come in handy when you ...

Discover More

Ignoring Case in a Comparison

Do you want Excel to take the case of your text into account when it does comparisons in a formula? The IF statement ignores ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 6 - 3?

2014-02-24 02:46:18

Ramin Aliyev

Great! it works with both LEFT and RIGHT commands.


2014-02-21 08:29:59

Jim Autrey

Excellent. Thanks, Peter. I'll add this routine to my personal.xlsb file.


2014-02-20 23:06:04

Peter Moran

Hi Jim,

I had this problem and found and modified the following:

Sub TrimALL()
' David McRitchie 2000-07-03 mod 2000-08-16 join.htm
' Trims Unwanted Chars from Cell Selection
' Loaded 22/5/03
'
Dim Cell As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'Also Treat CHR 0160, as a space (CHR 032)
Selection.Replace What:=Chr(160), Replacement:=Chr(32), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False

'Trim in Excel removes extra internal spaces, TRIM in VBA does not
On Error Resume Next 'in case no text cells in selection
For Each Cell In Intersect(Selection, _
Selection.SpecialCells(xlConstants, xlTextValues))
Cell.Value = Application.Trim(Cell.Value)
Next Cell
On Error GoTo 0
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

Peter Moran


2014-02-19 06:11:56

Jim Autrey

Thank you. I'll try that the next time I get a file that I can’t trim correctly.


2014-02-19 05:35:34

Michael (Micky) Avidan

@Jim,
=CODE(LEFT(A1)) will return the left most characters CODE.
The frequent NON-PRINTABLE characters codes are: 160, 254, 32 - where 32 reppresents a Space.
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)
ISRAEL


2014-02-18 05:12:30

Jim Autrey

Thanks.. Yes, TRIM usually works, but there are times when the alpha numeric characters are a specific distance from the left and are not deleted using TRIM. And no, the cell is not indented.

What I need is a "stronger" TRIM - one that deletes everything but alpha-numeric characters. Or, maybe a way to find out what the specific character is that TRIM won't delete.

Thanks for the post.


2014-02-17 09:21:53

Michael (Micky) Avidan

@Jim,
The function: TRIM will be more than happy to assist you.
Check it out in Excel's Help.
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)
ISRAEL


2014-02-16 15:58:25

Jim Autrey

Sometimes, there are one or more spaces preceding the alpha-numeric characters in the cell. Does Excel have a function to ignore the spaces? I'm sure a macro would be easy to set up, but a function would be simpler.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.