Google Sheets - Moving Row To Another Sheet Based On Specific Column
Very new to the Google Sheets script editing, but I'm trying to move rows between sheets. I've done this successfully using getLastRow however now I'm attempting to do this based o
Solution 1:
function onEdit(e) {
//Logger.log(JSON.stringify(e));
//e.source.toast(e.range.columnStart, e.value)
var sh=e.range.getSheet();
if(e.range.columnStart==8 && e.value=="Active") {
var tsh=e.source.getSheetByName("Active");
var target=tsh.getRange(getColumnHeight(8,tsh,e.source) + 1, 1);
sh.getRange(e.range.rowStart,1,1,sh.getLastColumn()).moveTo(target);
sh.deleteRow(e.range.rowStart);
}
}
function getColumnHeight(col,sh,ss){
var ss=ss||SpreadsheetApp.getActive();
var sh=sh||ss.getActiveSheet();
var col=col||sh.getActiveCell().getColumn();
var s=0;
var h=0;
if(sh.getLastRow()) {
var v=sh.getRange(1,col,sh.getLastRow(),1).getValues().map(function(r){return r[0];});
v.forEach(function(e,i){if(e==''){s++;}else{s=0;}h++;});
}
return (h-s);
}
Post a Comment for "Google Sheets - Moving Row To Another Sheet Based On Specific Column"