Google-sheets – Count number of line breaks in Google Sheets cell

google sheets

My spreadsheet looks like this:

Before

Is there a way with a formula to get in the B row the number of lines (including line breaks) as you see in the picture below?

After

Best Answer

Given your example setup:

=ArrayFormula(IF(A:A="",,LEN(A:A)-LEN(SUBSTITUTE(A:A,CHAR(10),""))+1))

To be clear, this counts number of lines, not number of line breaks. One line has zero line breaks. Two lines has one line break, etc.

This formula starts with the full length of each cell's contents (including line breaks) and then subtracts the length of each cell without those line breaks. That gives the total number of line breaks present, to which we add 1 to get the total number of lines.