Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Extract formula from a cell
- *
- * @param {reference} a cell reference from which to extract the formula
- * @return a string representation of the formula in {reference}
- * @customfunction
- */
- function CELLFORMULA(reference) {
- var ss = SpreadsheetApp;
- var sheet = ss.getActiveSheet();
- var formula = ss.getActiveRange().getFormula();
- var args = formula.match(/=\w+\((.*)\)/i);
- try {
- var range = sheet.getRange(args[1]);
- }
- catch(e) {
- throw new Error(args[1] + ' is not a valid range');
- }
- return range.getFormula();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement