1
votes

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

1
please add more details . I suppose you are counting cells means you must be having a google spreadsheet right ? - Vaibs
sorry for not too much details. Yes - guag.c
Why does this need to be in Javascript, you can do it within spreadsheets? Are you trying to do it in the browser or have you downloaded it to CSV? - Stefan Collier
Does this google spreedsheet your have is an input to some program or its like the google spreadsheet is opened in browser and you want a some javascript to run within greasymonkey which does the task ? still unclear on how you intend to read the google spreadsheet and why using javascript. - Vaibs
Yes I know how to do it within spreadsheets but I would like to know how it works via a simple script. And yes in the browser. - guag.c

1 Answers

2
votes

Try that...

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");

    }
  }
}