简体   繁体   中英

Google Sheets - Copy Cell -> Clear Cell -> Paste Cell

To work around my script/function refreshing it's calculation I had a script running that would copy the formula, clear the cell, and put the formula back in.

However, my script was somehow edited and now I can't figure out how to code this back...all I have is this base code that is not working and I don't remember how I made it work before...

I am missing a line or two of code but been racking my brain for a few hours =(

function RefreshSignups() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('L27:T29').activate();
  spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
  spreadsheet.getRange('K26').activate();
 spreadsheet.getCurrentCell().setValue('REFRESH');
};

Right now you're not actually copying any data / formula, nor pasting them back.

You probably want to use something like this:

var copyRange = spreadsheet.getRange('L27:T29');
var data = copyRange.getFormulas();
copyRange.clear({contentsOnly: true, skipFilteredRows: true});
copyRange.setFormulas(data);

But to be honest, I'm not sure I fully understand what you're trying to achieve with this, so might be good to provide more details about your goal if the above doesn't address it.

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