To filter data based on ID list found in other tab using App Script

Advertisements

I want to scrape data, but only filter data if Col13 from the data have the IDs listed in another tab. If I hardcode for 1 ID, I managed to do as below:

var sid = ss.getSheetByName('sid list').getRange('A2:A').getValues(); //capture list of IDs
        if(temp[13] == 243558369) {

        temp.push(counter)
        // console.log(temp)
        toPrint.push(temp)
        counter++
        }

This is the list of IDs to be captured var sid = ss.getSheetByName('sid list').getRange('A2:A').getValues(); //capture list of IDs

>Solution :

To filter data based on a list of IDs from another tab, you can modify your code to loop through the list of IDs and check if the value of Col13 matches any of the IDs in the list. Here’s an example of how you can achieve this:

var sidList = ss.getSheetByName('sid list').getRange('A2:A').getValues(); //capture list of IDs
var data = ss.getSheetByName('data').getDataRange().getValues(); //capture all data
var toPrint = [];
var counter = 1;
for (var i = 0; i < data.length; i++) {
  var temp = data[i];
  var col13 = temp[13];
  for (var j = 0; j < sidList.length; j++) {
    if (col13 == sidList[j][0]) {
      temp.push(counter);
      toPrint.push(temp);
      counter++;
      break;
    }
  }
}

Leave a ReplyCancel reply