'Add completed date to google sheet once I move it from the working sheet to the completed sheet
Good afternoon;
I am working on a google sheet with 2 columns "New Data" and "Completed". I have the New Data set with a check box that moves the row to the completed sheet once it is checked. Once on the completed sheet I would like to fill in a date and time stamp under comlumn E to show when it was moved to completed. What I have so far is listed below. Currently when it moves over from new data nothing happens. I also have a trigger set on addCompleteDate to work onEdit. Any help is appreciated.
function onEdit(e) {
const src = e.source.getActiveSheet();
const r = e.range;
if(src.getName() != "New Data" || r.columnStart != 6 || r.rowStart == 1) return;
const dest = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Completed");
src.getRange(r.rowStart, 1, 1 ,4).moveTo(dest.getRange(dest.getLastRow()+1,1,1,4));
src.deleteRow(r.rowStart);
}
function addCompleteDate(e){
const row = e.source.range.getRow();
const col = e.source.getSheetByName("Completed").columns[2];
if(col && col != "" && row > 1 ){
const currentDate = new Date();
e.source.getActiveSheet().getRange(row, 5).setValue(currentDate);
}
}
Solution 1:[1]
Just combine them together
function onEdit(e) {
const sh = e.range.getSheet();
if (sh.getName() == "New Data" && e.range.columnStart == 6 || e.range.rowStart > 1) {
const dsh = e.source.getSheetByName("Completed");
const dnr = dsh.getLastRow() + 1;
sh.getRange(e.range.rowStart, 1, 1, 4).moveTo(dsh.getRange(dnr, 1, 1, 4));
sh.deleteRow(e.range.rowStart);
dsh.getRange(dnr,5).setValue(new Date());
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Cooper |
