How to count the number of lines in a cell in Excel
Formula (Excel and Google Sheets)
=IF(A2="",0,LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1)Count the line breaks and add one: =IF(A2="",0,LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1).
- Result on the example
- one result per row in
B2, filled down toB6 - Works in
- Excel 2024 and Microsoft 365
- Google Sheets
- Same formula
See it work
The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.
How it works
Each new line in a cell starts after a line break, CHAR(10). Removing them all and comparing lengths gives the number of breaks, and the number of lines is one more. The IF keeps an empty cell at 0.
=IF(A2="",0,LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1)Result2
A2"Leave at front desk Call on arrival"The value in A2.
A2=""FALSEThe = operator tests whether the two sides are equal.
LEN(A2)35LEN: Number of characters.- text
A2"Leave at front desk Call on arrival"
- text
CHAR(10)" "CHAR: Character for a code number.- number
10
- number
SUBSTITUTE(A2,CHAR(10),"")"Leave at front deskCall on arrival"SUBSTITUTE: Replaces matching text.- text
A2"Leave at front desk Call on arrival" - old_text
CHAR(10)" " - new_text
""
- text
LEN(SUBSTITUTE(A2,CHAR(10),""))34LEN: Number of characters.- text
SUBSTITUTE(A2,CHAR(10),"")"Leave at front deskCall on arrival"
- text
LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))1The - operator subtracts.
LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+12The + operator adds.
IF(A2="",0,LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1)2IF: Returns one value if a test is true, another if false.- logical_test
A2=""FALSE - value_if_true
0not used - value_if_false
LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+12
- logical_test
In Google Sheets
The same formula works in Google Sheets: =IF(A2="",0,LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =IF(A2="",0,COUNTA(TEXTSPLIT(A2,CHAR(10)))) | 2, 1, 3… | Excel 365: split the cell at each line break and count the pieces. |
Common mistakes
- Lines created by Wrap Text aren't real line breaks and aren't counted; only Alt+Enter (or CHAR(10) in a formula) creates one.
- A line break at the very end adds an empty line to the count. Trim it first with a SUBSTITUTE or check
RIGHT(A2)=CHAR(10).
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Count the number of lines in a cell
B2, count the lines in the note (0 for an empty cell) and fill down to B6.Questions
How do I split the lines into separate cells?
Use =TEXTSPLIT(A2,CHAR(10)) for columns or =TEXTSPLIT(A2,,CHAR(10)) for rows.
Does this work in Google Sheets?
Yes. Google Sheets uses CHAR(10) for line breaks too.
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.