Hi everyone,
My goal is to copy the entire row of data from source data to destination range whenever the users select Transfer
or Update
in column E
. Based on my script, it only works perfectly for Employee No 1 (Peter).
For example, when I select transfer in cell E4
, the entire row of data from cell A4
to cell F4
will be copied to destination range (Row 1 in destination range as shown in the screenshot above). When I update certain cell, say cell C4
, and select Update
in cell E4
, the entire row will be copied again to the 2nd row of destination range as shown in the screenshot above.
However, when I select Transfer
of Update
in cell E5
or cell E6
the data been copied to destination range will still be the data from Peter (Row 3 in destination range as shown in the screenshot above).
I'm not sure how to fix this in my script and really hope to get some helps from you guys. This is the access to my google sheet for easier reference: https://docs.google.com/spreadsheets/d/1vfJYOAJT1Lqoj7uYQYftQ39Rl22FR9RWz04d1qYmRkg/edit?usp=sharing
This is my script:
function onEdit(e){
const dt = Utilities.formatDate(new Date(), 'Asia/Singapore', 'HH:mm:ss');
var ss = SpreadsheetApp.getActiveSheet ();
var direction = SpreadsheetApp.Direction
var aLast = ss.getRange("H"+(ss.getLastRow()+1)).getNextDataCell(direction.UP).getRow()
var destRange = ss.getRange(aLast+1,8);
if (e.range.columnStart == 5 && e.range.rowStart >= 4) {
if (e.value == 'Update' || e.value == 'Transfer') {
e.range.offset(0, 1).setValue(dt);
if(e.range.rowStart = 4) {
var order1 = ss.getRange ("A4:F4");
order1.copyTo (destRange, {contentsOnly: true});
} else if (e.range.rowStart = 5){
var order2 = ss.getRange ("A5:F5");
order2.copyTo (destRange, {contentsOnly: true});
} else if (e.range.rowStart = 6){
var order3 = ss.getRange ("A6:F6");
order3.copyTo (destRange, {contentsOnly: true});
}
source.copyTo (destRange, {contentsOnly: true});
} else {
e.range.offset(0, 1).setValue('');
}
}
}
Really appreciate for any helps and advice.