OzGrid

Count Lines in a Cell

< Back to Search results

 Category: [Excel]  Demo Available 

Count Lines in a Cell

 
 

Count Lines in a Range of Excel Worksheet Cells

Count Lines in a Cell or Range of Cell

 

To count the number of lines in any cell with Wrap Text on, use

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

Keep in kind that the formula above WILL return 1 for an empty cell, due to +1. Overcome that problem by use of this function;

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

The +(LEN(A1)>1) will either return TRUE (1) or FALSE (0).

f more than a single cell, you can repeat the formula for each cell in the range and SUM the results (My preference). Or use a single cell and nest the formula above with a 
SUM. E.g

=SUM(LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),""))+(LEN(A1)>1),LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+(LEN(A2)>1)...etc)

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

Count Between Date Ranges
Excel Count If With Multiple Criteria
Examples & Usage Of Excel CountIf Function
Examples & Usage Of Excel Counting Functions
Count Lines in a Cell

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.

 

Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft.


Gallery



stars (0 Reviews)