samedi 23 octobre 2021

For loop and If condition to find specific value in column and copy value of the same row in another spreadsheet with apps script

i am new into coding with google apps script and working on an project for my master thesis since a while.

I have an electrical device with several attachments. There is also a Recipe Collection for the device. In this Collection the first column is "Device", second column "Device_attachment" and third column "recipename".

The goal is that the code searches for "Device_attachment" in column 2 of the Recipe Collection. If it finds it, it should copy the "recipe_name", which is in the same row to another sheet.

With my code i have the problem that it does not just copy the recipe names of the specitic attachment i want it to copy. It also copies it for every other attachment. It is just the first part of the code. There are also Device_attachment2, Device_attachment3 and so on...

Is there a possibilty to put the condition "Device_attachment" in the last row of the code?? I am happy for every input or work arround.

Johanna

My problem is following:

  if(category == "Device"{
    if(attachment == "Device_attachment"){
     var sheet_RC=ss.getSheetByName("RecipeCollection");
       for (var i = 2; i <= sheet_RC.getLastRow(); i++ ){
         if(sheet_RC.getRange(i,2).getValue() == "Device_attachment") {
           var sheet_TP = ss.getSheetByName("TestPlan");
           sheet_RC.getRange(i,3).copyTo(sheet_TP.getRange(sheet_TP.getLastRow()+1,2));

}
}
}
}

Aucun commentaire:

Enregistrer un commentaire