Home > Mobile >  Google Sheet Retune Row Between Column Match Value in Google sheet script
Google Sheet Retune Row Between Column Match Value in Google sheet script

Time:03-15

The employee sheet contains the id of the employee in Column B. image may help to understand how this code should be work.

How can I get the rows matches the employee id?

I tried the following script and more but it doesn't seem to work.

Sample Image

function getTwoVal() {

  var idUrl = "idi";
  var sheet = SpreadsheetApp.openById(idUrl).getSheetByName("Sheet1");
  var data = sheet.getDataRange().getValues()

   var filteredRows = data.filter(function (row) {
     if (row[5] === '102' || row[5] === '106') {
       return row;
     }
   });

  console.log(filteredRows )

}

CodePudding user response:

Try

   var filteredRows = data.filter(function (row) {
     if (row[1] == '102' || row[1] == '106') {
       return row;
     }
   });

if id is in column B, use row[1] instead of row[5]

if id may be numeric, use == instead of ===

or, if you want between as the title suggests

   var filteredRows = data.filter(function (row) {
     if (row[1] >= 102 && row[1] <= 106) {
       return row;
     }
   });
  • Related