Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. /**
  2. * Extract formula from a cell
  3. *
  4. * @param {reference} a cell reference from which to extract the formula
  5. * @return a string representation of the formula in {reference}
  6. * @customfunction
  7. */
  8.  
  9. function CELLFORMULA(reference) {
  10. var ss = SpreadsheetApp;
  11. var sheet = ss.getActiveSheet();
  12. var formula = ss.getActiveRange().getFormula();
  13. var args = formula.match(/=\w+\((.*)\)/i);
  14. try {
  15. var range = sheet.getRange(args[1]);
  16. }
  17. catch(e) {
  18. throw new Error(args[1] + ' is not a valid range');
  19. }
  20. return range.getFormula();
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement