FormulaCraft

How to count the lines in a cell in Excel and Google Sheets

Topic:Text manipulation
Excel & Google Sheets
=LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1

Verified example

Computed by a real spreadsheet engine on the sample data below.

Notes
Line one
First line Second line
A B C
Single

=LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+11

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Select the cell containing multi-line text (line breaks inserted with Alt+Enter on Windows, Control+Option+Enter on Mac, or Control+Enter in Sheets).
  2. 2LEN(A2) counts all characters including line break characters.
  3. 3SUBSTITUTE(A2,CHAR(10),"") removes all line breaks.
  4. 4The difference LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),"")) equals the number of line breaks.
  5. 5Adding 1 converts line-break count to line count (n breaks = n+1 lines).
  6. 6Full formula: =LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1.

Tips

Working on a sheet you inherited? Run the Auditor on the whole file first — it flags every #REF!, #N/A, broken column pattern, and inconsistent formula in seconds, free, no signup.

Frequently asked

What if line breaks are CHAR(13) on some systems?

Excel Windows uses CHAR(10); some imported data may use CHAR(13) or both. Count both: =LEN(A2)-LEN(SUBSTITUTE(SUBSTITUTE(A2,CHAR(10),""),CHAR(13),""))+1.

Can I split multi-line cell content into separate rows?

In Google Sheets use =SPLIT(A2,CHAR(10),TRUE,TRUE). In Excel 365 use =TEXTSPLIT(A2,,CHAR(10)) to split on line breaks.

More on Text manipulation

See all →

Formulas used

Related tasks

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: