Why your COUNT function might not be working in Google Sheets

It can be frustrating when our Google Sheets functions don’t go the way we expect them to.

In this quick tutorial, we cover two common reasons why your COUNT function might not be running the way you expect it to. One beginner issue and one a little more advanced.

Counting Characters

When you count a range of numbers you use the COUNT function. However, if you are counting all the characters in a range you need to use the COUNTA function.

COUNTA counts all the values in a dataset including:

  • All duplicate values (You can use COUNTUNIQUE for just unique values).
  • Cells containing white space. That is, cells with spaces in them but no text.
  • Cells with a text string of zero. This is usually generated as a result of a formula.

To use COUNTA simply select a range or set of ranges.

=COUNTA(Range)

=COUNTA(C2:C25)

Counting the wrong number of values in a range generated from formulas

Quite often we are trying to template our Google Sheets for reuse in other projects or tasks. Take a look at this example:

Example of empty string in a cell Google Sheets
Click to Expand!

Here in Column K we have a formula that joins the first and last name together from columns I & J if it sees text in column J otherwise it will return an empty string. Here is the formula:

=IF(J2 = “”,“”, JOIN(” “,I2:J2))

This formula is then dragged all the way down the column so that it can be used again for another project.

The problem

The problem is that if we try and use COUNTA to get the values in Column K we will return a wrong number.

Why?

Because COUNTA will also count any cell that contains a string of characters with a length of zero (“”). So this will include and count all the cells in our range that contain our formula where we don’t want to display a value.

So how do we fix this?

The solution

Option 1

The most logical option is to try and use another column to reference your count. Unfortunately, this isn’t always possible.

Option 2

If your formula returns an error on an empty cell and you want to hide it, you could use the IFERROR function instead of the IF("","",... option to create an empty cell.

Here you wrap your formula inside the IFERROR function. You then have an optional argument to add what to do if there is an error or leave it blank if you don’t want anything to appear in the cell.

=IFERROR( your formula)

When you run a COUNTA on this column now it will return the correct count.

Option 3

If you can’t do either of these options then you could create a formula that checks the length of each string of data in each cell and if that cell length is greater than zero, count the cell.

First, you can get the length of a cell with the LEN function that takes a cell value. In our example, we will use the first cell item in our full name column K.

=LEN(K2)

We need to be able to use this LEN value on the selected range that we want to count. Here, we can use the ARRAYFORMULA function. This will allow us to put in a range of values in our LEN formula and get the length of each one. The result will be an array containing the length of values for each cell in the range.

=ARRAYFORMULA(LEN(K2:K))

Finally, we can use COUNTIF to count all the values in our new array of lengths that are greater than zero.

=COUNTIF(ARRAYFORMULA(LEN(K2:K)),“>1”)

Conclusion

Check out the video below for more information.

Do you have a clever way of dealing with this problem? I would love to hear about it in the comments below.

Did you enjoy the tutorial? Want to upskill and get a solid step-by-step course to become a pro at Google Sheets? Check out my course, Google Sheets: Learn the Essentials with Three Detailed Projects. Sign up today.

 
Google Sheets Shortcuts Mousepad
Google Sheets Shortcuts Mousepad
Want a fast track to boost your Spreadsheet efficiency? Grab one of these handy Google Sheets Shortcuts mousepads that I created from my store.
Google Sheets Shortcuts Mousepad Gel
Google Sheets Shortcuts Mousepad Ge

~Yagi

Create a seat booking form with Google Forms, Google Sheets and Google Apps Script

Google Forms, Google Sheets, Google Apps Script: SpreadsheetApp, FormApp

In this tutorial, we are going to build a simple seat booking Google Form. It will contain a registeree’s name and the session that they wish to attend.

Each time a registeree submits a request to book a seat for a session, that seat is taken from the list displaying only the remaining seats for that session for when the next user submits the form.

Take a look at the example below (click to expand the image):

Basic Seat Booking Form Google Forms

If all the seats have been booked for a seminar, then that seminar will not appear on the form. If all seats have been booked for all seminars, then the Google Form will close.

We will even create a  live list of attendees that we can embed on our website using Google Sheets.

Google Forms can’t do this for you out of the box. We will need to use Google Sheets to store our bookings and do some manipulation of the data. Then, we will use Google Apps Script to update the Google Form with the number of seats each time the form is submitted.

The Google Apps Script script has been prepared in a way that someone with limited coding skills can use it as a template by plugging in a few global variables. Alternatively, a more advanced user can incorporate the code into a larger project.

I’ll assume you have the basic abilities to create a simple Google Form and have used Google Sheets.

This tutorial can be followed as a useful step-by-step guide or if you are more confident, you can simply jump to the code using the contents below.

Continue reading “Create a seat booking form with Google Forms, Google Sheets and Google Apps Script”