Skip to content

Instantly share code, notes, and snippets.

@EthraZa
Last active March 16, 2021 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EthraZa/a1b959359cdb6df6484f36ce0783be18 to your computer and use it in GitHub Desktop.
Save EthraZa/a1b959359cdb6df6484f36ce0783be18 to your computer and use it in GitHub Desktop.
Google Sheets script: function refreshFormula(aToResfresh); For each cell in the array, force refresh the containing formula.
/**
* Google Sheets script: function refreshFormula(aToResfresh)
* For each cell in the array, force refresh the containing formula.
*
* @param {Array} aToResfresh The array of cells with formula to force refresh.
* @return {Void}
*/
function refreshFormula(aToResfresh = []) {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(),
sheet = spreadsheet.getActiveSheet(),
a = [];
aToResfresh.forEach(function(e) {
var cell = sheet.getRange(e);
a[e] = cell.getFormula();
if (a[e]) {
spreadsheet.toast('Refresh formula ' + e);
cell.setFormula(a[e].replace('=', '?'));
}
});
SpreadsheetApp.flush();
aToResfresh.forEach(function(e) {
var cell = sheet.getRange(e);
if (a[e]) {
cell.setFormula(a[e]);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment