mercredi 2 août 2017

IF Function - Google Scripts - multiple criteria

I'm trying to run an IF function to match the date in the first column to "last month" and the date in the last column to "newest date" and copy and paste all of the rows matching this criteria (excluding the first and last column) to the bottom of the list. This is the script I'm running and it isn't finding any matches when I know for a fact there are at least 100 rows matching this criteria:

function myFunction() {
  var MCS = SpreadsheetApp.openById('[ID REMOVED FOR THIS Q]');
  var MRB = MCS.getSheetByName('Media Rates Back');
  var MRBrange = MRB.getRange(1,1,MRB.getLastRow(),1).getValues();
  var dest = MRBrange.filter(String).length + 1;
  var LM = new Date();
  LM.setDate(1);
  LM.setMonth(LM.getMonth()-1);
  var LMs = Date.parse(LM);
  var Datenew = MRB.getRange(MRB.getLastRow(),MRB.getLastColumn()).getValue();
  var Datecol = MRB.getRange(1,6,MRB.getLastRow(),1).getValues();
  var Datenews = Date.parse(Datenew);

for(var i=0; i<MRBrange.length; i++) {

if(Date.parse(MRBrange[i])==LMs && Date.parse(Datecol[i])==Datenews ) {
  var NewRange = MRB.getRange(i,2,(MRB.getLastRow()-i),5);
  var NewRangeV = NewRange.getValues();
  var destination = MRB.getRange(MRB.getLastRow()+1,2);
Logger.log(NewRange);                                                  

NewRange.copyTo(destination);


}else{
  Logger.log(i);
}
}}

Any help would be appreciated!

Aucun commentaire:

Enregistrer un commentaire