Tell me more ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

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){ count++; }

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){ count++; }

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 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 at 18:15
1  
Added a link to my document.. hope you're able to see the script. – Raven Jan 24 at 19:42
Nicely styled sheet you have created !! I will take a look. – Jacob Jan Tuinstra Jan 24 at 20:13

1 Answer

up vote 0 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') {
    count[+data[i][j]][d]++;   
  }
}
share|improve this answer
Awesome, that worked perfect! Thanks a lot :) – Raven Jan 24 at 23:15

Your Answer

 
discard

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.