Reputation: 1
I tried this script to copy data from one sheet to another but when I update data in the source sheet and run the script the whole data gets copied .I just want the updated data get copied to target sheet without overlapping. Can anyone suggest what to do that
function copyPaste() {
var ss = SpreadsheetApp.openById("1zT24");
var source = ss.getSheetByName("prod");
var rangeSource = source.getDataRange();
var data = rangeSource.getValues();
var lr = rangeSource.getLastRow();
var lc = rangeSource.getLastColumn();
Logger.log(data);
var sss = SpreadsheetApp.openById("targetid");
var target = sss.getSheetByName("Sheet1")
target.getRange(target.getLastRow() + 1, 1, lr, lc).setValues(data);
}
Upvotes: 0
Views: 151
Reputation: 201388
Although I'm not sure whether I could correctly understand without overlapping
, if without overlapping
means all columns, how about the following modification?
target.getRange(target.getLastRow() + 1, 1, lr, lc).setValues(data);
target.getRange(target.getLastRow() + 1, 1, lr, lc).setValues(data);
target.getDataRange().removeDuplicates(); // Added
For example, if you want to remove the duplicated rows by the column "A", you can modify as follows.
target.getRange(target.getLastRow() + 1, 1, lr, lc).setValues(data);
target.getDataRange().removeDuplicates([1]); // Added
Upvotes: 1