Count number of non-empty lines in a multiline cell

ch1zra

New Member
Joined
Nov 3, 2016
Messages
8
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello everyone,

I am having trouble with one of the sheets at work that is created and maintained in quite a bad manner.
It contains multiline cells but not all lines are containing text, some are just plan char(10).
What I need is a way to count number of lines that are non-empty.
I can get number of total lines using
Code:
=(LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(10),"")))+1
but I am stuck on how to continue...
 

Attachments

  • xcl.png
    xcl.png
    11.8 KB · Views: 14

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
Well noted. I have updated it. 2021 & 365 for enterprise.
 
Upvote 0
Thanks for that. (y)
Which version does this need to work in?
 
Upvote 0
Ok, how about
Excel Formula:
=ROWS(TEXTSPLIT(A1,,CHAR(10),1))
 
Upvote 0
Solution
Like
Excel Formula:
=LET(a,TRIM(SUBSTITUTE(SUBSTITUTE(A1," ","|"),CHAR(10)," ")),LEN(a)-LEN(SUBSTITUTE(a," ",""))+1)
 
Upvote 0
Like
Excel Formula:
=LET(a,TRIM(SUBSTITUTE(SUBSTITUTE(A1," ","|"),CHAR(10)," ")),LEN(a)-LEN(SUBSTITUTE(a," ",""))+1)
Hm, this one is returning 8, but there are 9 blank lines.
 
Upvote 0
Not sure why, it should return the same value.
How about
Excel Formula:
=ROWS(FILTERXML("<k><m>"&SUBSTITUTE(A1,CHAR(10),"0</m><m>")&"</m></k>","//m[string-length()>1]"))
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,148
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top