I am trying to copy data from one sheet to another, when I change the value of one cell in the source sheet. I had this problem with other scripts that I tried to fire when editing a specific cell as well, not sure what I am doing wrong.
I found this code here (Google Apps Script - Copy data to different worksheet and append) that works well when I run it manually however when I wrap it so that when editing one cell nothing seems to happen, see below.
if (e.range.getA1Notation() === 'C1'){
var sss = SpreadsheetApp.openById('1ws8yg5_1k4ZZN2amfZ-cNvY-hUMUDGhbwnNPCGJhlAY'); //replace with source ID
var ss = sss.getSheetByName('export');
var range = ss.getRange('B3:C8');
var data = range.getValues();
var tss = SpreadsheetApp.openById('152JxdVi6Ssqz2ZZ65yDW5p5m0PnP63vApNgfP3jS_Pc'); //replace with destination ID
var ts = tss.getSheetByName('import'); //replace with destination Sheet tab name
ts.getRange(1, 2, 6,2).setValues(data); //you will need to define the size of the copied data see getRange()
}
}
Source Sheet: https://docs.google.com/spreadsheets/d/1ws8yg5_1k4ZZN2amfZ-cNvY-hUMUDGhbwnNPCGJhlAY/edit#gid=0
Destination Sheet: https://docs.google.com/spreadsheets/d/152JxdVi6Ssqz2ZZ65yDW5p5m0PnP63vApNgfP3jS_Pc/edit#gid=0
I tried to with creating a new trigger as well, something like this:
function createOnEditTrigger() {
var ss = SpreadsheetApp.openById(targetSpreadsheetID);
ScriptApp.newTrigger("CopyRange")
.forSpreadsheet(ss)
.onEdit()
.create();
}
but nothing is happening.