samedi 8 juillet 2023

Google sheets script if checkbox is checked than copy rows from one sheet to another

I have a small problem. I want to copy data from Sheet1 to Sheet2 with a button provided the checkbox is checked. In Sheet2, find the last row and then use the next one. After the data has been transferred, the cell content in Sheet1 should be deleted and the checkbox should be reset.

Can anyone help me with this?

Here is a screenshot from my sheet

I found this Code:

function button1() {
  var ss=SpreadsheetApp.getActive();
  var sht=ss.getSheetByName('tab1');
  var sht=ss.getSheetByName('tab2');
  var lastRow=sht.getLastRow();
  var rng=sht.getRange(1,1,lastRow,6);
  var rngA=rng.getValues();
  for(var i=0;i<rngA.length;i++)
  {
    if(rngA[i][2]==true)
    {
      sht.getRange(i+1,4).setValue(rngA[i][0]);
      sht.getRange(i+1,5).setValue(rngA[i][1]);
    }
  }
  SpreadsheetApp.flush();
}

But this code writes the data right next to the row. I would have to modify the code so that Sheet2 writes row by row starting with the last free row.




Aucun commentaire:

Enregistrer un commentaire