Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS

Excel Tutorial

Excel HOME Excel Introduction Excel Get Started Excel Overview Excel Syntax Excel Ranges Excel Fill Excel Move Cells Excel Add Cells Excel Delete Cells Excel Undo Redo Excel Formulas Excel Relative Reference Excel Absolute Reference Excel Arithmetic Operators Excel Parentheses Excel Functions

Excel Formatting

Excel Formatting Excel Format Painter Excel Format Colors Excel Format Fonts Excel Format Borders Excel Format Numbers Excel Format Grids Excel Format Settings

Excel Data Analysis

Excel Sort Excel Filter Excel Tables Excel Conditional Format Excel Highlight Cell Rules Excel Top Bottom Rules Excel Data Bars Excel Color Scales Excel Icon Sets Excel Manage Rules (CF) Excel Charts

Excel PivotTables

Excel PivotTable Intro Excel Create PivotTable Excel PivotTable Values Excel PivotTable Filter Excel PivotTable Group Excel Calculated Field Excel PivotChart

Excel Case

Case: Poke Mart Case: Poke Mart, Styling

Excel Functions

AND AVERAGE AVERAGEIF AVERAGEIFS CONCAT COUNT COUNTA COUNTBLANK COUNTIF COUNTIFS DATEDIF FILTER HLOOKUP IF IFERROR IFS INDEX INDEX MATCH LEFT LEN LOWER MATCH MAX MEDIAN MID MIN MODE NETWORKDAYS NPV OR PROPER RAND RIGHT ROUND SORT STDEV.P STDEV.S SUBSTITUTE SUM SUMIF SUMIFS SUMPRODUCT TEXTJOIN TODAY TRIM UNIQUE UPPER VLOOKUP XLOOKUP XOR

Excel How To

Convert Time to Seconds Difference Between Times NPV (Net Present Value) Remove Duplicates

Excel Cert

Excel Certificate

Excel Examples

Excel Exercises Excel Syllabus Excel Study Plan Excel Training

Excel References

Excel Keyboard Shortcuts


Excel LEN Function


Share

LEN Function

The LEN function is a premade function in Excel, which returns the number of characters in a text.

It counts every character: letters, digits, symbols and spaces.

It is typed =LEN and has one part:

=LEN(text)

Text: The text to count the characters of. This is usually a cell, like A2.

Note: Spaces are characters too. Poke Ball has 8 letters, but LEN returns 9, because the space is also counted.

How to use the LEN function:

  1. Select a cell (B2)
  2. Type =LEN
  3. Double click the LEN command
  4. Select the cell with the text (A2)
  5. Hit enter

Let's have a look at an example!

These are the products in the Poke Mart shop. Copy them and paste them into cell A1 to follow along:

Example data

AB
1ProductCharacters
2Poke Ball
3Great Ball
4Ultra Ball
5Potion
6Super Potion
7Hyper Potion
8Revive
9Antidote
10Paralyze Heal
11Awakening

Use the LEN function to count the characters in each product name, in column B:

AB
1ProductCharacters
2Poke Ball9
3Great Ball10
4Ultra Ball10
5Potion6
6Super Potion12
7Hyper Potion12
8Revive6
9Antidote8
10Paralyze Heal13
11Awakening9
=LEN(A2)

LEN counts the characters in A2. Poke Ball has 9 characters: 8 letters and 1 space.

The function is repeated with the filling function for each row, down to B11.

Paralyze Heal is the longest name, with 13 characters.

Note: LEN also works on numbers. It counts the digits of the value, not how the cell is formatted. A price of 1200 has a length of 4, even if the cell is formatted to show $1,200.00.



Find Extra Spaces With TRIM

Extra spaces are hard to see, but LEN counts them. Combine LEN with TRIM to find them.

TRIM removes the spaces before and after a text, and changes double spaces between words into single spaces. If the length is smaller after TRIM, the text had extra spaces.

These Pokemon names were copied from a sign-up form. Some of them have extra spaces:

ABCD
1NameLengthTrimmedExtra Spaces
2Pikachu770
3 Eevee651
4Snorlax 972
5Mr. Mime981
6Jigglypuff10100
7 Psyduck 1073

The formula in B2 counts all the characters:

=LEN(A2)

The formula in C2 counts the characters after TRIM has removed the extra spaces:

=LEN(TRIM(A2))

The formula in D2 shows the difference:

=B2-C2

The formulas are filled down to row 7.

Eevee has one space in front of the name. Snorlax has two spaces after it. Mr. Mime has two spaces between the words. Psyduck has two spaces in front and one after.

You can also count the extra spaces with one formula:

=LEN(A2)-LEN(TRIM(A2))

Note: Text copied from a web page can contain non-breaking spaces. They look like normal spaces, but TRIM does not remove them. If LEN still counts extra characters after TRIM, replace them with normal spaces first, with SUBSTITUTE(A2, CHAR(160), " ").


Check the Length of Codes

LEN is a quick way to check that codes have the right length.

The Poke Mart item codes have 13 characters, like PKB-0200-BALL. Use LEN inside an IF function to find the codes that were typed wrong:

AB
1Item CodeCheck
2PKB-0200-BALLOK
3GRB-600-BALLCheck
4ULB-1200-BALLOK
5POT-0300-MEDCheck
6SPT-07000-MEDSCheck
7HPT-1200-MEDSOK
=IF(LEN(A2)=13, "OK", "Check")

If the length of A2 is 13, the result is OK. If not, the result is Check.

GRB-600-BALL is missing a zero. POT-0300-MED is missing a letter. SPT-07000-MEDS has one digit too many.

Note: The different parts of the function are separated by a symbol, like comma , or semicolon ;

The symbol depends on your Language Settings.


Count a Character With SUBSTITUTE

LEN can also count how many times a character appears in a text. Remove the character with SUBSTITUTE, and compare the length before and after.

These shopping lists have one item after the other, separated by commas. Count the items in each list:

AB
1Shopping ListItems
2Poke Ball, Potion2
3Great Ball, Super Potion, Revive3
4Antidote1
5Ultra Ball, Hyper Potion, Revive, Awakening4
=LEN(A2)-LEN(SUBSTITUTE(A2, ",", ""))+1

SUBSTITUTE(A2, ",", "") removes the commas. The difference in length is the number of commas.

A list always has one more item than it has commas, so the formula adds 1.

For A2: Poke Ball, Potion has 17 characters. Without the comma it has 16. 17 - 16 + 1 = 2 items.

If a cell is empty, this formula still returns 1. Use it only on cells that have a list in them.


Related Functions

LEN is often used together with other text functions: TRIM, LEFT, RIGHT, MID and SUBSTITUTE.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.