Skip to content
xlsoffice. All Rights Reserved
  • Home
  • Excel For Beginners
  • Excel Intermediate
  • Advanced Excel For Experts

Lookup and Reference Examples

  • Extract data with helper column in Excel
  • Count unique text values with criteria
  • INDEX function: Description, Usage, Syntax, Examples and Explanation
  • How to get first row number in range in Excel
  • How to use Excel TRANSPOSE Function

Data Analysis Examples

  • How To Create Pareto Chart in Excel
  • Understanding Anova in Excel
  • Understanding Pivot Tables in Excel
  • How to Use Solver Tool in Excel
  • How to create Checklist in Excel

Data Validation Examples

  • Excel Data validation with conditional list
  • Excel Data validation specific characters only
  • Excel Data validation must begin with
  • Excel Data validation allow weekday only
  • How To Create Drop-down List in Excel

How to count line breaks in cell in Excel worksheet

by

This tutorial shows how to count line breaks in cell in Excel worksheet using example below.

To count total lines in a cell, you can use a formula based on the LEN, SUBSTITUTE, and CHAR functions.

Formula

=LEN(B5)-LEN(SUBSTITUTE(B5,CHAR(10),""))+1

Explanation

In the example, we are using this formula:

=LEN(B5)-LEN(SUBSTITUTE(B5,CHAR(10),""))+1

How the formula works

First, the LEN function counts total characters in the cell B5.

Worked Example:   Remove line breaks in a cell in Excel

Next SUBSTITUTE removes all “line returns” from the text in B5 by looking for CHAR(10) which is the character code for the return character in Windows.  LEN returns the result inside of a second LEN, which counts characters without carriage returns.

Worked Example:   If else in Excel

The second count is subtracted from the first, and 1 is added to the final result, since the number of lines is the number of returns + 1.

Mac version

On a Mac, the code for return character is 13 instead of 10, so use this formula instead:

=LEN(B5)-LEN(SUBSTITUTE(B5,CHAR(13),""))+1

Dealing with empty cells

The formula in the example shown will return 1 even if a cell is empty. If you need to guard against this problem, you can wrap the formula in IF statement like so:

=IF(ISBLANK(B5),0,LEN(B5)-LEN(SUBSTITUTE(B5,CHAR(10),""))+1)

Post navigation

Previous Post:

Clean and reformat telephone numbers using SUBSTITUTE function in Excel

Next Post:

How to display conditional message with REPT function in Excel

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Learn Basic Excel

Ribbon
Workbook
Worksheets
Format Cells
Find & Select
Sort & Filter
Templates
Print
Share
Protect
Keyboard Shortcuts

Categories

  • Charts
  • Data Analysis
  • Data Validation
  • Excel Functions
    • Cube Functions
    • Database Functions
    • Date and Time Functions
    • Engineering Functions
    • Financial Functions
    • Information Functions
    • Logical Functions
    • Lookup and Reference Functions
    • Math and Trig Functions
    • Statistical Functions
    • Text Functions
    • Web Functions
  • Excel VBA
  • Excel Video Tutorials
  • Formatting
  • Grouping
  • Others
  • Remove text by position in a cell in Excel
  • How to count specific words in a cell in Excel
  • DOLLAR function: Description, Usage, Syntax, Examples and Explanation
  • Remove leading and trailing spaces from text in one or more cells in Excel
  • ASC function: Description, Usage, Syntax, Examples and Explanation
  • How to calculate Quarter of Date in Excel
  • Get date from day number in Excel
  • Sum through n months in Excel
  • How to calculate project start date based on end date in Excel
  • Add days to date in Excel
  • FV function: Description, Usage, Syntax, Examples and Explanation
  • IRR function: Description, Usage, Syntax, Examples and Explanation
  • COUPDAYSNC function: Description, Usage, Syntax, Examples and Explanation
  • ODDFYIELD function: Description, Usage, Syntax, Examples and Explanation
  • Future value vs. Present value examples in Excel
© 2022 xlsoffice . All Right Reserved. | Teal Smiles