Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Determining the Length of a String.

Determining the Length of a String

Written by Allen Wyatt (last updated December 17, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


It is hard to imagine a function used more often with strings than the Len function. This simple little function returns the length of any string. The following are a few examples:

A = Len(MyString)
B = Len("This is a test")

The first line returns the length of the characters in the variable MyString. The second returns the number of characters between the quote marks (in this case, 14—remember that spaces count as characters).

If you want to determine the length of the information in a particular cell, you follow a bit different approach:

C = Len(ActiveCell.Text)

When this line is executed, it returns the length of whatever is displayed in the currently selected cell. It is important to note that since it relies on the .Text property, the code returns the length of what is displayed in the cell, not what is actually contained within the cell.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12404) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Determining the Length of a String.

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

Deriving an Absolute Value in a Macro

Need to figure out an absolute value within your macro code? It's easy to do using the Abs function, described in this tip.

Discover More

Slow Excel Response Times

Many people use Excel on a notebook computer, so they can do work at the office and elsewhere. In some situations, Excel ...

Discover More

Understanding At Least Line Spacing

Line spacing is used to control how close lines are to each other within a paragraph. Word allows you to specify several ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Saving Information in a Text File

The VBA programming language provided with Excel allows you to create and modify text files quite easily. Here's how to ...

Discover More

Running Macros on Hidden Worksheets

Excel allows you to hide worksheets so that they aren't visible to those using your workbook. Hiding worksheets has a ...

Discover More

Unprotecting Groups of Worksheets

Unprotecting a single worksheet is relatively easy. Unprotecting a whole lot of worksheets is harder. Here's how you can ...

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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 1 + 1?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu 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.