I want to increment the value in the A1
cell.
function increment(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("A1");
cellValue = cell.getValue("A1");
cell.SetValue(cellValue + 1);
}
How can I do that?
I want to increment the value in the A1
cell.
function increment(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("A1");
cellValue = cell.getValue("A1");
cell.SetValue(cellValue + 1);
}
How can I do that?
Share Improve this question edited Dec 8, 2014 at 13:54 Stéphane Bruckert 23k14 gold badges99 silver badges135 bronze badges asked Dec 8, 2014 at 13:18 Maher M.Maher M. 3492 silver badges18 bronze badges1 Answer
Reset to default 8You are calling getValue()
with an argument. This function does not take any arguments, as can be seen in the documentation:
https://developers.google./apps-script/reference/spreadsheet/range#getValue()
function increment(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange("A1");
//Returns the value of the top-left cell in the sheet
var value = range.getValue();
range.setValue(value + 1);
}