Reputation: 35
I want to do an action if the selected cell is formula, how do I do?
Some command like isformula() of Google Sheets.
Ex.: if (cell == "formula"?) {make something} else {make something}
Upvotes: 2
Views: 2769
Reputation: 85
getFormula return true if there is a formula and false if it doesn't. There is no need to check the string for "=".
if (range.getFormula()) {
ui.alert('has formula: ' + range.getFormula());
} else {
ui.alert('no formula: ' + range.getFormula());
}
Upvotes: 5
Reputation: 18717
google-apps-script function
getFormula()
may be handy:
getFormula()
Output. String
Returns the formula (A1 notation) for the top-left cell of the range, or an empty string if the cell is empty or doesn't contain a formula.
Please try:
if (range.getFormula().substring(0, 1) === '='
{
// there is a formula
}
substring(0,1)
gets the left symbol:
https://www.w3schools.com/jsref/jsref_substring.asp
Upvotes: 2