0

This is part of code. Rest of code works but on this part Ive stuck and I dont know why!

function rndDATgen(F){

var fRNG = SpreadsheetApp.getActiveRange();
var fROW = fRNG.getRow();

var ss = SpreadsheetApp.getActiveSpreadsheet();
var SRCsheet = ss.getSheetByName("Dates");
var DSTsheet = ss.getActiveSheet();


var rngDATE = SRCsheet.getDataRange();
var valDATE = rngDATE.getValues();

var colSRNG = DSTsheet.getRange('A1:ZZ7');
var colVALUES = colSRNG.getValues();

var stDAT = DSTsheet.getRange("S1").getValue();
var enDAT = DSTsheet.getRange("S2").getValue();

var DSTclr = 7; 
var DSTrow = 7;
var nDAT = 0;
var DSTlr = 7;
var DSTc = DSTsheet.getRange(1, 9, 500,1);
var DSTvalues = DSTc.getValues();


while (DSTvalues[DSTlr - 1][0] != ""){
   DSTlr++;
}
  DSTlr = DSTlr - 1;

var totRNGstat = DSTsheet.getRange('T7:T' + DSTlr);
var totRNGvalSTAT = totRNGstat.getValues();

var totRNG = SRCsheet.getRange('A1:A100');
var totRNGval = totRNG.getValues();

var totRNGdat = DSTsheet.getRange('S7:S' + DSTlr);
var totRNGvalDAT = totRNG.getValues();

var stDATrow = 0;
var enDATrow = 0;

for (var i=0; i<100; i++) {
if (totRNGval[i] == stDAT) {
  stDATrow = i + 1;
}
}

In this last chunk of code Ive tried to iterate to find where in array is certain date (start date in this case = stDAT and range totRNGval)! By trying to return stDAT and totRNGval[i], both returns date in same format 01/01/2018. I ve tried as value too, but still no luck!

for (var i=0; i<100; i++) {
if (totRNGval[i] == stDAT) {
stDATrow = i + 1;
}
}

When I return value, it is always 0 but for sure there is excact date in range as start date.

Ive also check manually and it is same value (without floats) and it does find it with any other function: MATCH, VLOOKUP...! Ive tried changing == to ===, but no luck!

Why in loop start date isnt recognized when comparing with elements of array?

Mr K
  • 111
  • 13

1 Answers1

0

On the end I've bypassed this problem, simply by adding formula in "T1:T2" =Match(T1, DATES!A:A,0) and calling value from T1 & T2 with getValue().

Still, If anyone knows why my script didn't worked on first please I would like to learn it!

Mr K
  • 111
  • 13