Last active
March 16, 2021 20:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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