Wednesday, June 5, 2024
98
rated 0 times [  100] [ 2]  / answers: 1 / hits: 7708  / 10 Years ago, mon, december 8, 2014, 12:00:00

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?


More From » google-apps-script

 Answers
0

You are calling getValue() with an argument. This function does not take any arguments, as can be seen in the documentation:



https://developers.google.com/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);
}

[#40768] Saturday, December 6, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rociom

Total Points: 287
Total Questions: 88
Total Answers: 101

Location: Oman
Member since Wed, Nov 17, 2021
3 Years ago
;