Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing arguments from a button in google app script

I want to be abble to click on a button in a Google Sheet and add +1 to a particular cell.

I have this script :

function AddOne(inputCell) {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange(inputCell).activate();
  spreadsheet.getCurrentCell().setValue(spreadsheet.getCurrentCell().getValue() + 1);
};

On the button, I assigned the script

AddOne('C6')

When I click on the button, i have the error Script function AddOne('C6') could not be found.

Can you please help me resolve this matter ?

Thanks in advance.

like image 255
Thanos Avatar asked Sep 18 '25 23:09

Thanos


1 Answers

An addOne button that adds one to the current cell

function addOne() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getActiveSheet();
  var rg=sh.getActiveCell();
  rg.setValue(rg.getValue()+1);
}

Just go to insert/Drawing pick a plus shape. Save it and place it on your sheet and attach the script with the three dots in the upper right hand corner. Select any cell that you want to increment and press the plus sign and it get's incremented by one. You could make a minus one too.

like image 122
Cooper Avatar answered Sep 20 '25 18:09

Cooper