In a Google Spreadsheet: How can I count the rows of a given area that have a value? All hints about this I found up to now lead to formulas that do count the rows which have a not empty content (including formula), but a cell with
=IF(1=2;"";"") // Shows an empty cell
is counted as well.
What is the solution to this simple task?
A simpler solution that works for me:
It counts both numbers, strings, dates, etc that are not empty
For me, none of the answers worked for ranges that include both virgin cells and cells that are empty based on a formula (e.g.
=IF(1=2;"";"")
)What solved it for me is this:
=COUNTA(FILTER(range, range <> ""))
counta
: "Returns a count of the number of values in a dataset"Note:
CountA
considers""
to be a value. Only cells that are blank (press delete in a cell to blank it) are not counted.Google support: https://support.google.com/docs/answer/3093991
countblank
: "Returns the number of empty cells in a given range"Note:
CountBlank
considers both blank cells (press delete to blank a cell) and cells that have a formula that returns""
to be empty cells.Google Support: https://support.google.com/docs/answer/3093403
If you have a range that includes formulae that result in
""
, then you can modify your formula fromto:
EDIT: the function is
countblank
, notcountblanks
, the latter will give an error.Make another column that determines if the referenced cell is blank using the function "CountBlank". Then use count on the values created in the new "CountBlank" column.
Solved using a solution i found googling by Yogi Anand: https://productforums.google.com/d/msg/docs/3qsR2m-1Xx8/sSU6Z6NYLOcJ
The example below counts the number of non-empty rows in the range A3:C, remember to update both ranges in the formula with your range of interest.
Also make sure to avoid circular dependencies, it will happen if you for example count the number of non-empty rows in A:C and place this formula in the A or C column.
You can define a custom function using Apps Script (Tools > Script editor) called for example
numNonEmptyRows
:And then use it in a cell like this
=numNonEmptyRows(A23:C25)
to count the number of non empty rows in the rangeA23:C25
;