Search code examples
google-apps-scriptgoogle-sheetsgoogle-sheets-macros

Automatically Paste a cell value into the last row of another googlesheet


I have a sheet named 'Titles' in column C values are constantly being entered. Once a value is entered in column C, I need that newest value to automatically be copied into the sheet named 'Translations' in Column D at the next available row (beneath the latest value copied).

As values are being pasted in 'Titles' column C how can this script constantly be running, so I don't need to click run a script every time for the new title to display in the translations sheet.

function I have so far copying from another case

function copyPaste() {
  var ss=SpreadsheetApp.getActive();
  var srcsh=ss.getSheetByName('Titles');
  var dessh=ss.getSheetByName('Translations');
  var srcrg=srcsh.getRange('C2:C1000');
  var data=srcrg.getValues();
  var desrg=dessh.getRange(dessh.getLastRow() + 1,1,99,1);
  desrg.setValues(data);
}

Solution

  • You may need to make this a installable trigger.

    function onEdit(e) {
      e.source.toast('entry');
      if(e.range.getSheet().getName()=='Titles' && e.range.columnStart==3) {
        e.source.toast('past conditional');//etc
        const tsh=e.source.getSheetByName('Translations');
        tsh.getRange(tsh.getLastRow()+1,4).setValue(e.value);//e.value is the value added to columnC of 'Title' sheet
      }
    }