简体   繁体   中英

Google Sheets Copying and Pasting from one sheet to another based on cell value

I'm working with code that I found researching my issue. I've posted it below. The issue I'm having is that the date an item is returned is naturally going to change as the week progresses. I'm at a loss as to how I would alter the code to copy and paste the row if any combination of "Returned (date)" is input into column 8.

function onEdit() {
    // moves a row from a sheet to another when a magic value is entered in a column
    // adjust the following variables to fit your needs
    // see https://productforums.google.com/d/topic/docs/ehoCZjFPBao/discussion
    var sheetNameToWatch = "Checked Out";
    var columnNumberToWatch = 8; // column A = 1, B = 2, etc.
    var valueToWatch = "Returned 1/1";
    var sheetNameToMoveTheRowTo = "Returned";

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = SpreadsheetApp.getActiveSheet();
    var range = sheet.getActiveCell();

    if (sheet.getName() == sheetNameToWatch && range.getColumn() == columnNumberToWatch && range.getValue() == valueToWatch) {
        var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
        var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
        sheet.getRange(range.getRow(), 1, 1, sheet.getLastColumn()).moveTo(targetRange);
        sheet.deleteRow(range.getRow());
    }
}

There is a Google Sheets formula called ISDATE() you could just add a helper column that checks whether the input date is valid. Then just check the return value of this cell is TRUE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM