Excel Get Text Length: How to Use the LEN Function
In this article
To get the length of a text string in Excel, use the =LEN(text) function. This formula counts every single character within a cell, including letters, numbers, special symbols, and spaces. For example, if cell A1 contains the word "Apple", =LEN(A1) will return 5; if it contains "Apple Pie", it will return 9 because the space is counted as a character.
What You'll Need
- A computer with Microsoft Excel installed (any version from 2007 to the latest Microsoft 365) or a web browser using Excel for the Web.
- A dataset containing the text strings you wish to measure.
- Basic knowledge of how to enter a formula into a cell.
Step-by-Step
- Identify your target cell: Locate the cell that contains the text you want to measure. For this guide, we will assume your text is in cell A2.
- Select the output cell: Click on the empty cell where you want the character count to appear (for example, cell B2).
- Enter the equals sign: Type
=into the cell. This tells Excel that you are starting a formula rather than entering plain text. - Type the LEN function: Type
LEN(. The LEN function is the built-in Excel tool specifically designed to return the number of characters given to it. - Reference the text cell: While the parenthesis is open, click on cell A2 or type
A2. Your formula should now look like=LEN(A2). - Close the parenthesis and press Enter: Type the closing parenthesis
)and press the Enter key on your keyboard. Excel will now display the total character count for that cell. - Apply to multiple rows: If you have a long list of text in column A, you do not need to type the formula for every row. Click the small green square (the fill handle) at the bottom-right corner of cell B2 and drag it down to the bottom of your list. Excel will automatically adjust the cell reference (e.g., changing A2 to A3, A4, etc.) for each row.
Common Mistakes
One of the most frequent errors users make is forgetting that spaces are characters. If you are trying to count only the letters in a word but your data has a trailing space at the end (e.g., "Excel "), the LEN function will return 6 instead of 5. This often happens when data is imported from other software or typed manually by different users.
Another common mistake is trying to use the LEN function on a cell that contains a formula that results in a number. While LEN can handle numbers, it treats them as text strings. If a cell contains a formatted currency value like "$1,200.00", the LEN function counts the dollar sign, the comma, and the decimal point, which may not be the numerical length you are looking for.
Users also occasionally confuse LEN with other counting functions. For instance, using COUNT or COUNTA will tell you how many cells in a range contain data, but it will not tell you how many characters are inside a single cell. Always ensure you are using LEN for character counts and COUNT functions for cell counts.
Tips
Removing Extra Spaces: To get an accurate count of the actual text without accidental leading or trailing spaces, wrap your LEN function around the TRIM function. The formula =LEN(TRIM(A2)) tells Excel to first remove all spaces from the start and end of the text and then count the remaining characters. This is essential for cleaning data before uploading it to a database with strict character limits.
Counting Specific Characters: If you want to count how many times a specific character (like a comma or a dash) appears in a cell, you can use a clever combination of LEN and SUBSTITUTE. For example, to count how many commas are in cell A2, use: =LEN(A2)-LEN(SUBSTITUTE(A2,",","")). This works by taking the total length and subtracting the length of the text after all commas have been removed; the difference is the number of commas.
Combining with IF for Validation: You can use LEN to create a data validation check. If you have a column for US Zip Codes that must be exactly 5 digits, you can use a formula like =IF(LEN(A2)=5, "Valid", "Invalid"). This allows you to quickly scan your spreadsheet for entries that are too short or too long.
Handling Non-Printable Characters: Sometimes data imported from the web contains hidden characters (like non-breaking spaces) that TRIM cannot remove. In these cases, use the CLEAN function: =LEN(CLEAN(A2)). This removes non-printable characters that might be artificially inflating your character count.
Troubleshooting
The formula returns #NAME? This usually happens if the function name is misspelled. Ensure you have typed LEN and not LENGTH. Excel uses the shorthand "LEN" for this specific operation.
The result is 0 but the cell looks full: Check if the cell is formatted as a formula or if the text is actually an image/object placed over the cell. If the cell contains a formula that results in an empty string (""), LEN will return 0.
The count is higher than expected: This is almost always due to invisible characters. To investigate, try clicking into the cell and pressing the End key to see if the cursor lands several spaces past the last visible letter. If it does, use the TRIM function as mentioned in the Tips section.
The formula doesn't update when text changes: Ensure your workbook is set to "Automatic Calculation." Go to the Formulas tab, click Calculation Options, and make sure "Automatic" is selected. If it is set to "Manual," you must press F9 to refresh the character counts.
Frequently Asked Questions
Does LEN count punctuation?
Yes, the LEN function counts every single character, including periods, commas, exclamation points, and any other symbols present in the cell.
Can LEN count the characters in multiple cells at once?
No, the standard LEN function only accepts a single text string. To get the total length of multiple cells, you must sum them, such as =SUM(LEN(A2), LEN(A3), LEN(A4)) or use an array formula like =SUMPRODUCT(LEN(A2:A10)).
Does LEN count line breaks (Alt+Enter)?
Yes, line breaks within a cell are counted as characters. Depending on your operating system, a line break is typically counted as one character.
How do I count only letters and ignore numbers?
Excel does not have a single function to do this. You would need to use a complex array formula or a User Defined Function (VBA) to strip out numbers before applying the LEN function.
Will LEN work on cells containing dates?
Yes, but it will count the characters of the underlying date serial number (the number Excel uses to store dates) rather than the formatted date you see on the screen. To count the visible date characters, use =LEN(TEXT(A2, "mm/dd/yyyy")).