Skip to content Skip to sidebar Skip to footer

Take Values ​from One Sheet And Save Them On The Other Sheet Based On The Id

I tried to create a script that takes values ​​from one sheet and saves them on the other sheet based on the ID. Unfortunately, the script only saves the first value. What's wr

Solution 1:

Most likely the inconsistency arises in the for loop as you are using the same variable i as iterator for both the main and inner loops, as a result the values overwrite. Change the second loop variable, for example to j (and its references in the internal loop), for example:

for (var i=0;i<AllValues.length;i++){
   var CurrentRow = AllValues[i];
   var Id1 = CurrentRow[0]; //col with ID Sheet1 
   var kwota = CurrentRow[7]; //col with rate Sheet 1
   Logger.log(CurrentRow); 
     
   for (var j=0;j<AllValues2.length;j++){
      var CurrentRow2 = AllValues2[j];
      var Id2 = CurrentRow2[0]; //Col with ID Sheet2  
      var kwota2 = CurrentRow2[12]; //Col with rate Sheet2
      //Logger.log(Id2);  
     
      //Set Values   
      if (Id1 == Id2){
        var setRow2 = j + FirstRow2;
        docelowysheet.getRange(setRow2, 13).setValue(kwota);
        //Logger.log(CurrentRow[7]);
      } 
}

Post a Comment for "Take Values ​from One Sheet And Save Them On The Other Sheet Based On The Id"