简体   繁体   中英

Move rows based on “yes” to new book/sheet

I have found a ton of these scripts. But not what I need. I am looking for a script that I can link to a trigger. When triggered every row with a "yes" in column 8 (H) Will be moved to another sheet With its on separate Google Sheets ID. (Sheet 1). My script works. BUT it takes everything to the new sheet. And I only need the ones that have "yes" in column 8 (H). I have found scripts that do it on edit to the same book. But not on trigger to another Google Sheets ID.

function CopyDataToNewFile() {
    var sourceSheet = SpreadsheetApp.openById('Source ID').getSheetByName('Admin'),
        sourceValues = sourceSheet.getRange(4, 1, sourceSheet.getLastRow(), sourceSheet.getLastColumn()).getValues(),
        targetSheet = SpreadsheetApp.openById('Destination ID').getSheetByName('Sheet1');
    targetSheet.getRange(targetSheet.getLastRow() + 1, 1, sourceValues.length, sourceValues[0].length).setValues(sourceValues);
    sourceSheet.getRange(6, 1, sourceSheet.getLastRow(), sourceSheet.getLastColumn()).clearContent();
}

Add a way to filter sourceValues . For this, you could add loop or to use filterByText(Object[][] data, int columnIndex, String value) from 2D arrays library or another similar library.

Perhaps the easiest solution is to use FILTER or QUERY built-in functions to filter data prior to get it by the script.

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