dimanche 28 avril 2019

How do i get this code to copy only the rows that mach my object matching criteria? currently if copies every row

currently this code copies every row and not the ones that match my criteria

i had some issues getting it to loop. hence the loggers.

I'm quite new to this.

  function searchAnotherSheetAndReturnRows(){
Logger.clear()
  var tss = SpreadsheetApp.openById('1dX5MMLXGsG_S_KzRhOcquOp00VhzRBSlTCkyw'); // tss = target spreadsheet
  var ts = tss.getSheetByName('Sheet1'); // ts = target sheet
var sss = SpreadsheetApp.openById('1ImDswr6ADS7t4HKIFHpntykN2LS7Mmd-cls34'); // sss = source spreadsheet
  var ss = sss.getSheetByName('Page1'); // ss = source sheet
 var tslast_row = ts.getLastRow();

var i=0;
Logger.log(i)

for (var i = 1; i < tslast_row; i++) {
Logger.log(i)

Logger.log(tslast_row);
 var ssSearch1 = ss.getRange(2,1).getValue();
     Logger.log(ssSearch1); 
 var tsSearch1 = ts.getRange(i,1).getValue();
     Logger.log(tsSearch1);

if (ssSearch1 == tsSearch1); {


     var  tsSearch1Range = ts.getRange(i,1,1,7);
     Logger.log(tsSearch1Range);
     var range2Copy = tsSearch1Range.getValues();//  Copies data from root sheet
     Logger.log(range2Copy);
     var last_row = ss.getLastRow();
     Logger.log(last_row);
     var last_row = last_row+1;
     Logger.log(last_row);
     ss.getRange(last_row,1,1,7).setValues(range2Copy);// Adds  root sheet data to target


}
}

}


Aucun commentaire:

Enregistrer un commentaire