Libreoffice-Calc: Count number of rows and ouput total below list

libreoffice-calc

How to write a macro that counts the number of columns that contain data and prints the result at the bottom of the list?

For example, if the data is:

|1|2|3|
|a| | |
|1| |3|

The final table would be:

|1|2|3|
|a| | |
|1| |3|
|=|=|=|
|3|1|2|

Best Answer

There are different approaches:

  • Use COUNTIF(), comparing the rows range with an empty string:

    =COUNTIF(A1:A3;"<>''")

  • use COUNTBLANK() and subtract the result from the sum of rows:

    =ROWS(A1:A3)-COUNTBLANK(A1:A3)

In both cases, just enter the formula in A4 and drag it to the right, LO Calc will adapt the cell references automatically.

Related Question