mercredi 2 juin 2021

Google Add Script Loop and Array

I am trying to loop on every cell on my spreadsheet and look for a certain cell that is not equal to 100. I was able to loop over each cell for each column and row. As a test, I input 5 or 6 cells with different value. I am trying to use Array to get the value and show it to my Log, but every time I did that it always show me 1.0 answer.

Google App Script:

function countValue() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getActiveRange().getValues();
  spreadsheet.forEach(function(row) {
    row.forEach(function(col){
      if (col != 100) {
        var notNumber100 = [];
        var invalidNumber = notNumber100.push(col);
        Logger.log(invalidNumber);
      };
    });
  });
}

Below is the log that I get every time I run the script. The invalid value that I put has a length of 5 or 6.

enter image description here

Aucun commentaire:

Enregistrer un commentaire