Spreadsheet Practice

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 to B6
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

  1. A2"Leave at front desk Call on arrival"

    The value in A2.

  2. A2=""FALSE

    The = operator tests whether the two sides are equal.

  3. LEN(A2)35

    LEN: Number of characters.

    • textA2"Leave at front desk Call on arrival"
  4. CHAR(10)" "

    CHAR: Character for a code number.

    • number10
  5. SUBSTITUTE(A2,CHAR(10),"")"Leave at front deskCall on arrival"

    SUBSTITUTE: Replaces matching text.

    • textA2"Leave at front desk Call on arrival"
    • old_textCHAR(10)" "
    • new_text""
  6. LEN(SUBSTITUTE(A2,CHAR(10),""))34

    LEN: Number of characters.

    • textSUBSTITUTE(A2,CHAR(10),"")"Leave at front deskCall on arrival"
  7. LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))1

    The - operator subtracts.

  8. LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+12

    The + operator adds.

  9. IF(A2="",0,LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1)2

    IF: Returns one value if a test is true, another if false.

    • logical_testA2=""FALSE
    • value_if_true0not used
    • value_if_falseLEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+12

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.

FormulaResultWhen 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

In 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.