Web Applications Stack Exchange is a question and answer site for power users of web applications. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to count a number of specific responses from a form where the response can be left empty, zero or any other number 'd'.

The following code:

var data = sheet.getRange("B2:L").getValues();

var d = 0;
if (data[i][j] == d){

assumes that an empty cell == 0 is true, thus counting the wrong number of cells that actually hold the value zero

var d = 0;
if (data[i][j] != '' && data[i][j] == d){

or any variation with != null / != "" does not seem to work for me

EDIT : Link to document. I think you can see the script if you make a copy.

share|improve this question
Can you share a doc with us? – Jacob Jan Tuinstra Jan 24 '13 at 17:53
Added the complete code (at least the counting part) will be helpful as well. Can you edit your question? – Jacob Jan Tuinstra Jan 24 '13 at 18:15
Added a link to my document.. hope you're able to see the script. – Raven Jan 24 '13 at 19:42
Nicely styled sheet you have created !! I will take a look. – Jacob Jan Tuinstra Jan 24 '13 at 20:13
up vote 1 down vote accepted

When counting for the different d values, you need to check whether the objects in the array are string or number based:

for (var j=1; j<lastColumn-1; j++) {
  if (typeof data[i][j] !== 'string') {
share|improve this answer
Awesome, that worked perfect! Thanks a lot :) – Raven Jan 24 '13 at 23:15

You can also use the following to determine empty, zero-value or 'else'.

 if (cell === "") // empty cell
 if (cell == 0)  // zero-value cell
share|improve this answer
The title doesn't correspond to the problem faced. I had to dig in deep to understand real problem. This isn't resolving the problem – Jacob Jan Tuinstra Sep 17 '13 at 13:58

Have you tried isBlank() function?

share|improve this answer
OP is after a script solution. – Jacob Jan Tuinstra Nov 19 '14 at 12:55
@JacobJanTuinstra, isBlank() is a Google Apps Script function (Check the link). – Punchlinern Nov 20 '14 at 7:26
@Punchlinern Didn't know that... – Jacob Jan Tuinstra Nov 20 '14 at 9:27
You learn something everyday :) – Punchlinern Nov 20 '14 at 9:28
@phermous: Have you tried it? – Jacob Jan Tuinstra Nov 20 '14 at 9:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.