Count the sum of the number of lines in a column

Ian Y

New Member
Joined
Nov 18, 2023
Messages
37
Office Version
  1. 2019
Platform
  1. Windows
In Google Sheets, if you want to count the sum of the number of lines in all cells in column A, this function can be used:

Code:
=counta(A1:A) + sum(arrayformula(len(regexreplace(A1:A, "[^\n]", ""))))

What’s the equivalent in Excel 2019? I tried the same function, and it doesn’t work and shows the result as #NAME?
 
One way:

=SUMPRODUCT((LEN(A1:A1000)-LEN(SUBSTITUTE(A1:A1000,CHAR(10),""))+(A1:A1000<>"")))
 
Upvote 1
Solution

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Did you confirm the formula with Ctrl+Shift+Enter, not just Enter?
Oh, I didn't do that.

I just tried Ctrl+Shift+Enter, and the only difference I saw is that function text in the function field are now wrapped in curly brackets ({}), and the number they yields are the same (1005 and 1000).
 
Upvote 0
and the number they yields are the same (1005 and 1000).
OK, so blank cells in the range then? Not sure what highest row number you will need , but try something like this.
Will you have a lot of these calculations to do in this worksheet?

23 11 19.xlsm
AB
1
2This is a line. Yet another line. How are you? What time is it?8
3
4More lines go here. Today is sunday. This year is 2023.
5
6
7Just one more line.
8
Count lines
Cell Formulas
RangeFormula
B2B2=SUM(LEN(A2:A1000)-LEN(SUBSTITUTE(A2:A1000,CHAR(10),""))+(A2:A1000<>""))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
@Peter_SSs,

As for the amount of calculations, I probably will have 90 columns in total. Each column represent one day. The number of rows would be about 400 ~ 500 rows in total.
 
Upvote 0
That works, too! Thanks for showing that Sum can also work!
You're welcome. Thanks for the confirmation. (y)


I probably will have 90 columns in total. Each column represent one day. The number of rows would be about 400 ~ 500 rows in total.
OK, thanks. That is not all that large. I thought if the amount of rows was very big, and there were a lot of them, the SUMPRODUCT formulas might be somewhat slow to calculate. With your amount of data I don't think any difference either way would be noticeable. :)
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,069
Members
449,090
Latest member
fragment

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