Count number of line breaks in a cell

This tutorial shows how to count the number of line breaks in a cell using an Excel formula, with the LEN and SUBSTITUTE functions

EXCEL FORMULA 1. Count number of line breaks in a cell

EXCEL

Count number of line breaks in a cell

=LEN(B5)-LEN(SUBSTITUTE(B5,CHAR(10),""))+1
GENERIC FORMULA

=LEN(cell)-LEN(SUBSTITUTE(cell,CHAR(10),""))+1

ARGUMENTS
cell: A string from which to count the number of line breaks.

EXPLANATION

This formula uses the SUBSTITUTE function with char(10) to remove the line breaks from a cell and then applies the LEN function to count the number of character from the cell without line breaks. The LEN function is also used to calculate the number of characters from a cell which includes line breaks. The formula then subtracts the number of characters derived from a cell that excludes line breaks from number of characters derived from a string that includes line breaks.

RELATED TOPICS

Related Topic Description Related Topic and Description
How to count the number of spaces in a string

RELATED FUNCTIONS

Related Functions Description Related Functions and Description
The Excel SUBSTITUTE function replaces characters with another in a specified string
The Excel LEN function returns the number of characters in a specified string