Take the 2-minute tour ×
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 '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
1  
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

3 Answers 3

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') {
    count[+data[i][j]][d]++;   
  }
}
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
     doEmptyCellStuff();
 else
 if (cell == 0)  // zero-value cell
     doZeroValueCellStuff();
 else
     dValueCellStuff();
share|improve this answer
1  
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 at 12:55
1  
@JacobJanTuinstra, isBlank() is a Google Apps Script function (Check the link). –  Punchlinern Nov 20 at 7:26
    
@Punchlinern Didn't know that... –  Jacob Jan Tuinstra Nov 20 at 9:27
1  
You learn something everyday :) –  Punchlinern Nov 20 at 9:28
    
@phermous: Have you tried it? –  Jacob Jan Tuinstra Nov 20 at 9:28

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.