Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in


How to count the line breaks in cell in Excel?

If the contents are too long to enter the cell, we usually use line breaks to break the contents so than the contents can completely be displayed in cell as below screenshot shown. Could you ever tried to count the number of the line breaks in a cell?
doc count line break 1

Count line breaks in cell with formula

Count line breaks in cell with VBA

Count line breaks in cell with formula

To count line breaks in a cell, you can try this formula.

Select a cell next to the string you want to count line breaks, type =LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),"")), and press Enter key. See screenshot:
doc count line break 2


1. If you work with Mac system, try this formula =LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(13),""))

2. Above formulas only count manual line breaks.

Count line breaks in cell with VBA

Here is a VBA code that also can count the line breaks in a cell in Excel.

1. Press Alt + F11 keys to enable Microsoft Visual Basic for Applications window.

2. Click Insert > Module, copy and paste code to the Module.

VBA: Count manual line break

Public Sub CountLines()
    Dim xStrLen As Double
    Dim xChrLen As Double
    With Range("A2")
        xStrLen = Len(.Text)
        xChrLen = Len(Replace(.Text, Chr(10), ""))
    End With
    MsgBox "There are " & xStrLen - xChrLen & " line breaks"

doc count line break 3

3. Press F5 key, a dialog pops out to tell you the number of line breaks.
doc count line break 4

Count times a word appears

If you want to count the times a specific word appears in a single cell or a range, you can try Count times a word appears of Kutools for Excel, it may make a big favor for you.
doc formula 1

Recommended Productivity Tools for Excel

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.