I need to run a script which contains the logic: If isNumber, Then DoSomething.
I've run other such if then tests such as if blank, and if cell contains "x". It should be simple but I can't find a solution. I've tried getNumberFormat, innum, isnumber, etc.
function ifIsNumber() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getActiveSheet();
var substring1 = s.getRange("A1").getNumberFormat();
s.getRange("B1").setValue(substring1);
}
This code checks cell A1 and returns in cell B1 the string "0.###############", for both cells containing numbers AND text. How can I identify which cells are numbers?
This will check if A1 is a number:
Google Apps Script could use most of the JavaScript methods and operators.
One alternative to check if an object is a number is to use typeof.
The following code will return the type of the value of the cell specified by the reference.
Example of use as a custom function
If cell
A1
number
.string
.