Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. 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

by Allen Wyatt
(last updated January 7, 2017)

4

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(ActiveSheet.Range(ActiveWindow.Selection.Address))

When this line is executed, it returns the length of whatever is in the currently selected 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, and 2016. 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

Removing Leading Spaces in a Table

If you work with data imported from the Web or with documents prepared by others, you may have tables that have leading ...

Discover More

Jumping to a Relative Section

Navigating through a long document can be challenging, at times. Here's a way you can move forward or backwards in your ...

Discover More

Deleting Additional Clocks

Windows can display up to three separate clocks so you can keep track of what time it is in various time zones. If you ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Copying Worksheet Code Automatically

When creating a workbook to be used by others, you may want any worksheets they add to the workbook to contain some ...

Discover More

Recording a Macro

One of the most common ways of creating macros is to use Excel's macro recorder. This tip shows how easy it is to use the ...

Discover More

Workbook Events

You can create macros that run whenever Excel detects a certain event happening within an entire workbook. This tip ...

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 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 four more than 2?

2017-01-09 22:43:17

Greg

The statement as shown in the tip is a fully qualified cell location within a workbook..specifically the actual currently selected cell.

You could use a similar statement to reference a cell on another sheet in the same workbook, or even a cell in another workbook so long as the file path was a constant...but I don't have the syntax handy to share.( ie, an external reference)


2017-01-07 19:13:50

Bob Beechey

To reveal the number of characters in active cell (string or not) you could use:
C = Len(ActiveCell.Text)


2017-01-07 17:51:18

John M

When I read the title of the tip, I didn't realize it was a VBA. For non VBA use, the LEN function works much the same way. For example "=LEN(D1)" (without the quotes) will return the length of the string in cell D1. This works with cells formatted as text or general.


2017-01-07 06:28:35

Alex B

Is the full specification,
Len(ActiveSheet.Range(ActiveWindow.Selection.Address)),
an Excel 2016 requirement ?

In Excel 2010 with selection being A2 both,
c = len(activecell)
c = len(cells(2,1))
seem to work fine for me.

I hear that Excel 2016 gets a bit tricker with the allowing of multiple windows.


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.