I am using the code posted here that moves a row based on the value of a column, but I want to edit it so that it does the opposite: moves a column to a new sheet based on the value of a row. This is what I have so far:
function onEdit(event) {
// source data in sheet named Blocks
// sheet column is moved to named Ordered
// test row with word "Done" is row 1
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Blocks" && r.getRow() == 1 && r.getValue() == "Done") {
var column = r.getColumn();
var numRows = s.getLastRow();
var targetSheet = ss.getSheetByName("Ordered");
var target = targetSheet.getRange(targetSheet.getLastColumn() + 1, 1);
s.getRange(column, 1, 1, numRows).copyTo(target);
s.deleteColumn(column);
}
}
The problem is, when I tested it, it only moved the first row of that column. I want it to move the entire column and then delete it from the original sheet.
Can anyone tell me where I went wrong?
function onEdit(e) {
//e.source.toast('Entry');
var sh = e.range.getSheet();
if(sh.getName() == "Blocks" && e.range.rowStart == 1 && e.value == "Done") {
//e.source.toast('Ordered1')
var tsh = e.source.getSheetByName("Ordered");
var target = tsh.getRange(1,tsh.getLastColumn() + 1);
sh.getRange(2, e.range.columnStart, sh.getLastRow() -1).copyTo(target);
sh.deleteColumn(e.range.columnStart);
}
}
I used Active/Done datavalidation on row one and I only moved from row two to last row and then deleted the entire column including the validated cell.