How to Use LEN Function in Excel – 7 Examples

This an overview of the LEN function.

Excel LEN Function

 


Syntax

The LEN function is described with the following syntax:

=LEN (text)

Arguments

Argument Required or Optional Value
text Required The text to calculate the length.

Note

  • LEN reflects the length of text as a number.
  • This function works with numbers, but number formatting is not included.
  • The LEN function returns zero for empty cells.

Example 1 – Compare Name Length

The sample dataset showcases two groups of students.

Steps:

  • Select a cell and enter the following formula.
=LEN(B5)=LEN(C5)

Compare Between Name Lengths

Formula Breakdown

  • LEN(B5) will return the total length of B5: 4.
  • LEN(D5) will return the total length of D5: 4.
  • =LEN(B5)=LEN(D5) will compare the numbers.
  • Press ENTER to see the output.

  • Drag down the Fill Handle to AutoFill the rest of the cells.

 Excel LEN Function


Example 2 – Count the Characters Including Leading and Trailing Spaces

Steps:

=LEN(B5)

Count Characters Including Leading and Trailing Spaces

  • Press ENTER to see the output.

  • Drag down the Fill Handle to AutoFill the rest of the cells.

Excel LEN Function

  • In C5, the total is 32: there are no leading and trailing spaces.
  • In B6, the output is 33 characters: in C6 as there is a leading space.
  • In B7, the output is 33 characters: in C7 as there is a trailing space.
  • In B8, the output 34 characters: in C6 as there is a leading and a trailing space.

Example 3 – Count Characters Excluding Leading and Trailing Spaces

Steps:

  • Select a cell (C5) and enter the following formula.
=LEN(TRIM(B5))

Count Characters Excluding Leading and Trailing Spaces

 

  • Press ENTER to see the number of characters excluding leading and trailing spaces.

  • Drag down the Fill Handle to AutoFill the rest of the cells.

Excel LEN Function


Example 4 – Count the Number of Characters Before or After a Given Character

Steps:

  • Enter the following formula in a selected cell.
=LEN(LEFT($B5, SEARCH("-", $B5)-1))

Count Number of Characters Before or After a Given Character

  • Press ENTER to see the output.

  • Drag down the Fill Handle to AutoFill the rest of the cells.

Excel LEN Function


Example 5 – Extract Data from a String

Steps:

  • Select a cell and enter the following formula.
=RIGHT(C5,LEN(C5)-FIND(" ",C5))

Extract Data from a String

  • Press ENTER to see the output.

  • Drag down the Fill Handle to AutoFill the rest of the cells.

Excel LEN Function


Example 6 – Count Specific Characters in a Cell

Steps:

  • Select a cell and enter the following formula.
=LEN(C5)-LEN(SUBSTITUTE(C5,"M",""))

Count Specific Character in a Cell

  • Press ENTER to see the output.

  • Drag down the Fill Handle to AutoFill the rest of the cells.

 Excel LEN Function


Example 7 – Summarize a Specific Character Count in a Range

Find the total number of mobile phones by counting the number of Ms.

Steps:

  • Select a cell (C5) and enter the following formula.
=SUMPRODUCT(LEN(C5:C10)-LEN(SUBSTITUTE(C5:C10, "M","")))

Summarize Specific Character Count in a Range

  • Press ENTER to see the output.

 Excel LEN Function


Practice Section

Practice here.

Practice Section


Common Errors with Excel LEN Function

Common Errors When They Show
#NAME The function name is incorrect.
#REF! The formula is used in two different workbooks and the source workbook is closed.

Download Practice Workbook


<< Go Back to Excel Functions | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Md. Abdullah Al Murad
Md. Abdullah Al Murad

Md. Abdullah Al Murad is a computer engineer who loves exploring Excel and VBA programming. Programming, to him, is a time-saving tool for efficiently managing data, files, and internet tasks. He is proficient in C, C++, Python, JavaScript, HTML, SQL, MySQL, PostgreSQL, Microsoft Office, and VBA and goes beyond the basics. He holds a B.Sc. in Computer Science and Engineering from American International University-Bangladesh. He has transitioned into the role of a content developer. Beyond his work, find... Read Full Bio

2 Comments
  1. Cell [B29] = DDDF-98765432-110 [sample data in cell B29]
    Right(), Left() and Len() formula is required to obtain: 98765432

    data between the two dashes is required to be retrieved, please.

    I have solved it as:

    =LEFT(RIGHT(B29,LEN(B29)-FIND(“-“,B29)),FIND(“-“,RIGHT(B29,LEN(B29)-FIND(“-“,B29)))-1)

    • Hello Falak Niaz,

      Certainly! Your formula correctly extracts the data between the two dashes. Your feedback and suggestion will be helpful for other users.
      If you want you can simplify it by using MID function.

      =MID(B29, FIND(“-“, B29) + 1, FIND(“-“, B29, FIND(“-“, B29) + 1) – FIND(“-“, B29) – 1)

      Thanks for sharing your formula.

      Regards
      ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo