How do you get the literal value (the formula) from a cell instead of the result value?
EXAMPLE DESIRED:
I had the same problem and tried to use the formula that Rubén created, but had a limitation. I couldn't use these formula inside of another one (I was trying to make a mid()). So made a different approach that worked:
function CELLFORMULA(reference) {
var ss = SpreadsheetApp;
var sheet = ss.getActiveSheet();
var formula = ss.getActiveRange().getFormula();
re = /cellformula\((.*)\);/g;
args = re.exec(formula);
try {
var range = sheet.getRange(args[1]);
}
catch(e) {
throw new Error(args + ' is not a valid range');
}
return range.getFormula();
}