Reputation: 21
Needing your kind help to solve my Google script issues.
I have 3 Tabs on a google spreadsheet, I want to transfer data from 2 tabs into 3rd tab. and this to be performed when I do edit on any of 2 tabs. My code is getting error on 2nd OnEdit function as below.
"TypeError: Cannot read property 'source' of undefined onEdit @ macros.gs:22"
My code is here.
function PurposeDrivenMission() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('\'Purpose Driven Mission\'!D171').copyTo(spreadsheet.getRange('\'All Links\'!GE1364'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
};
function onEdit(e1) {
const range = e1.source.getRange('\'Purpose Driven Mission\'!A1:AA2000');
PurposeDrivenMission();
}
function EightProductivity() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('\'Eight Productivity Systems\'!D72').copyTo(spreadsheet.getRange('\'All Links\'!GD2'), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
};
function onEdit(e2) {
const range = e2.source.getRange('\'Eight Productivity Systems\'!A1:AA2000');
EightProductivity();
}
Upvotes: 0
Views: 88
Reputation: 64032
How about this one?
Any edit on the source sheets moves data to the destination
function onEdit(e) {
const sh = e.range.getSheet();
const shts = ['Source1SheetName','Source2SheetName'];
const idx = shts.indexOf(sh.getName());
if( ~idx) {
const drgs = ['drg1','drg2'];//ranges is A1Notation
const srgs = ['srg1','srg2'];
const dsh = e.source.getSheetByName('Destination SheetName');
const ssh = e.source.getSheetByName(shts[idx]);
ssh.getRange(srgs[idx]).copyTo(dsh.getRange(drgs[idx]), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
}
}
Upvotes: 1