简体   繁体   中英

How to change this script to not to delete but replace with empty cells

So I have this Script:

function Copy() {
    var sh = SpreadsheetApp.getActive().getSheetByName('Form Responses')
    var range = sh.getDataRange().offset(1, 0);
    var data = range.getValues();
    var ts = SpreadsheetApp.openById('x').getSheetByName('backup')
    ts.getRange(ts.getLastRow() + 1, 1, data.length, data[0].length).setValues(data);
    sh.deleteRows(2, range.getNumRows() - 1);
}

How should I change it to not delete that that line but replace it with empty cells? Because I'm referring to those cells in another sheet and every time after the script runs those references got to #referror. And I'm guessing its because of the deleting.

I understood that you want to clear cell values but you don't want to delete rows by sh.deleteRows(2, range.getNumRows() - 1); . If my understanding is correct, how about this modification? You can achieve it using clear() .

From :

sh.deleteRows(2, range.getNumRows() - 1);

To :

sh.getRange(2, 1, range.getNumRows() - 1, sh.getLastColumn()).clear();

Reference :

If I misunderstand your question, I'm sorry.

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