Count number of characters in a cell
This tutorial shows how to count the total number of characters, including spaces, in a cell through the use of an Excel formula or VBA
Example: Count number of characters in a cell
=LEN(B5)
|
This formula uses the Excel LEN function to return the number of characters, including spaces, from a selected cell. In this example we are returning the number of characters in cell B5, which comprises of nine characters, including one space.
|
Sub Count_number_of_characters_in_a_cell()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'count the total number of characters in a cell
ws.Range("C5") = Len(ws.Range("B5"))
ws.Range("C5") = Len(ws.Range("B5"))
End Sub
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code.
Cell Reference: Select the cell that holds the characters that you want to count by changing the cell reference ("B5") in the VBA code.
Worksheet Selection: Select the worksheet which contains the cell from which to count number of characters by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name 'ws' in the VBA code.
Output Range: Select the output range by changing the cell reference ("C5") in the VBA code.
Cell Reference: Select the cell that holds the characters that you want to count by changing the cell reference ("B5") in the VBA code.
Worksheet Selection: Select the worksheet which contains the cell from which to count number of characters by changing the Analysis worksheet name in the VBA code. You can also change the name of this object variable, by changing the name 'ws' in the VBA code.
EXPLANATION
This tutorial shows how to count the number of characters, including spaces, in a cell by using of an Excel formula or VBA.
Both the Excel formula and VBA make use of the LEN function to count the number of characters in a cell.
FORMULA
=LEN(text)
=LEN(text)
ARGUMENTS
text: The string from which to extract the characters.
text: The string from which to extract the characters.
RELATED TOPICS
Related Topic | Description | Related Topic and Description |
---|---|---|
Count number of columns in a range | How to count the total number of columns in a range using Excel and VBA methods | |
Count number of rows in a range | How to count the total number of rows in a range using Excel and VBA methods | |
Count numeric characters in a cell | How to count the total number of numeric characters in a cell using Excel and VBA methods | |
Count number of cells in a range | How to count the total number of cells in a range using Excel and VBA methods | |
Count number of characters in a cell excluding spaces | How to count the total number of characters in a cell, excluding spaces, using Excel and VBA methods |
RELATED FUNCTIONS
Related Functions | Description | Related Functions and Description |
---|---|---|
LEN Function | The Excel LEN function returns the number of characters in a specified string |