I'm trying to use the script function appendrow() to move rows to sheet that has drop-down and checkbox data validation (data validation is present on the source sheet too and mirrors the target sheet's data validation). The problem I'm having is that rows are being appended all the way down at row 1000 on the target sheet. When I remove the drop-downs, it appends the rows correctly. I need the data validation to be present though, in case changes need to be made to those cells. The data validation is applied to several columns (e.g. F2:F).
I need to know how to insert the row after the header because the dropdowns and checkboxes are apparently viewed as content according to the appendrow() function.
Current script:
function onEdit(e) {
var ss = e.source,
sheet = ss.getActiveSheet(),
range = e.range,
targetSheet,
columnNumberToWatch = 14;
if (sheet.getName() === "Pending Bookings" && e.value === "CONFIRMED" &&
e.range.columnStart === columnNumberToWatch) {
targetSheet = "Confirmed Bookings"
} else if (sheet.getName() === "Confirmed Bookings" && e.value === "" &&
e.range.columnStart === columnNumberToWatch) {
targetSheet = "Pending Bookings"
}
ss.getSheetByName(targetSheet)
.appendRow(sheet.getRange(e.range.rowStart, 1, 1, sheet.getLastColumn())
.getValues()[0])
sheet.deleteRow(e.range.rowStart);
}
function appendRow() { SpreadsheetApp.getActiveSheet().appendRow(['','Yes','Maybe','No Way', 'Come back tommorow and try again']) }
and there is no problem at all as long as the validation is in it's default state (i.e. nothing selected). If one is selected near the bottom then that next line is where appending begins. – Cooper