Skip to main content

Count lines which are separated by line breaks in a cell or a range

Author: Xiaoyang Last Modified: 2020-01-02

This article is talking shout how to count the number of lines which are separated by line breaks in a cell or a range of cell by using formula in Excel.

Count the number of lines in a cell

Count the number of lines in a range of cells

Count the number of lines in a cell

To count total lines in a cell, you can use the combination of the LEN, SUBSTITUTE and CHAR functions.

1. Please apply the below formula:


2. And then, drag the fill handle down to the cells that you want to apply this formula, and all lines in each cell have been counted, see screenshot:

Explanation of the formula:
  • LEN(A2): count the number of total characters in cell A2;
  • SUBSTITUTE(A2,CHAR(10),""): is used to replace all line break characters with empty characters in cell A2;
  • LEN(SUBSTITUTE(A2,CHAR(10),"")): count the number of all the characters in cell A2 without line break characters;
  • LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1: the first count subtracts the second count, and add 1 to get the result.

Note: With the above formula, you will get the result 1 if a cell is empty, to overcome this problem, please apply the following formula:


Count the number of lines in a range of cells

If you need to count the total number of lines from a range of cells, the following formulas ca help you.

1. Enter or copy the below formula into a blank cell where you want to output the result:

=SUM(LEN(A2:A4)-LEN(SUBSTITUTE(A2:A4,CHAR(10), ""))+1)

2. And then, press Ctrl + Shift + Enter keys together, and the number of the total lines in a range has been calculated, see screenshot:

Note: To fix the above formula when there are blank cells in the range, please use the below formula:


Relative functions used:

  • LEN:
  • The LEN function returns the number of characters in a text string.
  • The Excel SUBSTITUTE function replaces text or characters within a text string with another text or characters.

More articles:

  • Count Keywords Cell Contains Based On A List
  • If you want to count the number of keywords appears in a cell based on a list of cells, the combination of the SUMPRODUCT, ISNUMBER and SEARCH functions may help you to solve this problem in Excel.
  • Show specific text based on value in Excel
  • Supposing, you have a list of values, now, you would like to show a specific text based on the value. For example, if cell value is greater than 1000, then “Increase” text is displayed in another column as below screenshot shown. To deal with this task, both the REPT and IF functions can do you a favor.
  • Check if cell equals any value in list
  • For example, I have a list of text strings in column A, and now, I want to check if cell value in this column equals any value in another list of column E. If equals, display TRUE, otherwise, a FALSE value is displayed as below screenshot shown.

The Best Office Productivity Tools

Kutools for Excel - Helps You To Stand Out From Crowd

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates  |  Delete Blank Rows  |  Combine Columns or Cells without Losing Data  |  Round without Formula ...
Super VLookup: Multiple Criteria  |  Multiple Value  |  Across Multi-Sheets  |  Fuzzy Lookup...
Adv. Drop-down List: Easy Drop Down List  |  Dependent Drop Down List  |  Multi-select Drop Down List...
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus  |  Design View  |  Big Formula Bar  |  Workbook & Sheet Manager | Resource Library (Auto Text)  |  Date Picker  |  Combine Worksheets  |  Encrypt/Decrypt Cells  |  Send Emails by List  |  Super Filter  |  Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters ...)  |  50+ Chart Types (Gantt Chart ...)  |  40+ Practical Formulas (Calculate age based on birthday ...)  |  19 Insertion Tools (Insert QR Code, Insert Picture from Path ...)  |  12 Conversion Tools (Numbers to Words, Currency Conversion ...)  |  7 Merge & Split Tools (Advanced Combine Rows, Split Excel Cells ...)  |  ... and more

Kutools for Excel Boasts Over 300 Features, Ensuring That What You Need is Just A Click Away...


Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)

  • One second to switch between dozens of open documents!
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Edge and Firefox.
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Leave your comments
Posting as Guest
Rate this post:
0   Characters
Suggested Locations