LEN Function Excel
In this Article
This Excel Tutorial demonstrates how to use the Excel LEN Function in Excel to count the number of characters, with formula examples.
LEN Function Description:
The LEN Function Counts number of characters in a text string.
Syntax and Arguments:
The Syntax for the LEN Formula is:
Function Arguments ( Inputs ):
text – A string of text.
The LEN Function is very useful when working with other text functions. Such as Left, Right, or Mid.
And finally, one of the more useful roles the LEN function can serve is validating a range that needs to be a specific length.
In this example a user needs to input 5 digit Zipcodes in range A2:A10. You will notice in the picture that every time a user inputs cell content that does not equal 5 characters the cell color changes, making it very easy to audit.
This is achieved by using the LEN function with conditional formatting, here’s how:
1. Select the Range or cell to apply Conditional Formatting to
2. Select Format on the Main Menu
3. Select Conditional Formatting
4. In the dropdown change Cell value is to Formula is
5. Enter =LEN(A2:A10)<>5
6. Click the Format… button and choose the format to apply if the condition is met. I changed the Pattern or background color
7. Click OK, OK
Here’s a snippet of my Conditional Formatting window using LEN
LEN Examples in VBA
You can also use the LEN function in VBA. Type:
For the function arguments (text, etc.), you can either enter them directly into the function, or define variables to use instead.
Executing the following VBA statements
Range("B2") = Len(Range("A2"))
Range("B3") = Len(Range("A3"))
Range("B4") = Len(Range("A4"))
Range("B5") = Len(Range("A5"))
Range("B6") = Len(Range("A6"))
will produce the following results
Return to the List of all Functions in Excel
How to use the LEN Function in Excel:
To use the AND Excel Worksheet Function, type the following into a cell:
After entering it in the cell, notice how the AND formula inputs appear below the cell:
You will need to enter these inputs into the function. The function inputs are covered in more detail in the next section. However, if you ever need more help with the function, after typing “=LEN(” into a cell, without leaving the cell, use the shortcut CTRL + A (A for Arguments) to open the “Insert Function Dialog Box” for detailed instructions:
For more information about the LEN Formula visit the