guag.c
guag.c

Reputation: 29

Google apps script count if

My problem has been resolved by Juan (below in italic my first request). However I am trying a second thing :

I have a google spreadsheet with 2 columns. 1st column with names (jeff, daniel...) 2nd column with value (1, 2, 3...) I would like to create a simple script which reads all the row from the top and output the number with value 20 or more. And to display the results in cell C2. I cant figure out how to do it. Thank you a lot for the one who can do it.

How is it possible to write a simple script to know "how many value are above 20 in my column B" (still considering my spreadsheet for my first question) and to get the result in cell D2 for example ?

Thanks again for your time. I am really struggling with that

Upvotes: 1

Views: 12715

Answers (1)

jbra95
jbra95

Reputation: 909

Try this

function myFunction() {
  var data = SpreadsheetApp.getActive().getSheetByName("Sheet1").getDataRange().getValues();
  
  for (var i =0; i < data.length; i++){
    var column2 = data[i][1];


    if (column2 >= 20){
      var column3 = SpreadsheetApp.getActive().getSheetByName("Sheet1").getRange(i +1, 3).setValue("value to add on column 3");
  
    }
  }
}

Upvotes: 3

Related Questions