0

I'm trying to add buttons to several rows that would either add or subtract value from the designated row. Here's an image to show you what I want to do.

Rows with plus and substract buttons

I've reached to this script:

function plusB1() {
  ss=SpreadsheetApp.getActiveSpreadsheet()
  s=ss.getActiveSheet()
  var currVal=s.getRange("B1").getValue()
  var plusVal= currVal +1
  s.getRange("B1") .setValue(plusVal)
}

function minusB1() {
  ss=SpreadsheetApp.getActiveSpreadsheet()
  s=ss.getActiveSheet()
  var currVal=s.getRange("B1").getValue()
  var minusVal= currVal -1
  s.getRange("B1") .setValue(minusVal)
}

Which does what I want, except only in the first row. I could repeat creating custom functions for each row, but it seems very inefficient to me. Is there a way to have a couple of functions that gathers info about which row this button was pressed at?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Juan B
  • 3
  • 2
  • 1
    Does this answer your question? [button click is only working on Windows & not working on Android mobile sheet](https://stackoverflow.com/questions/57840757/button-click-is-only-working-on-windows-not-working-on-android-mobile-sheet) – TheMaster Jan 29 '20 at 13:51
  • Could you please share a sample of your sheet? How are you assigning the functions to the buttons? Are they just image hovering in the sheet? – Raserhin Jan 29 '20 at 14:13

2 Answers2

0

You cant. It's not good idea for Google Sheets and Scripts.

Because you can't pass a parameter or check which button was pressed.

If you continue, you will need to create 10 methods that would call for each button with different parameters inside.

function plus(range) {
  ss=SpreadsheetApp.getActiveSpreadsheet()
  s=ss.getActiveSheet()
  var currVal=s.getRange(range).getValue()
  var plusVal= currVal +1
  s.getRange(range) .setValue(plusVal)
}

function minus(range) {
  ss=SpreadsheetApp.getActiveSpreadsheet()
  s=ss.getActiveSheet()
  var currVal=s.getRange(range).getValue()
  var minusVal= currVal -1
  s.getRange(range) .setValue(minusVal)
}

function plusA(){
  plus("A")
}

function minusA(){
  plus("A")
}

etc ...

contributorpw
  • 4,739
  • 5
  • 27
  • 50
0

Adding and Subtracting

function onEdit(e) {
  e.source.toast('Entry');
  var sh=e.range.getSheet();
  if(sh.getName()=='Sheet233' && e.range.columnStart==3) {
    e.source.toast("incr");
    e.range.setValue("FALSE");
    e.range.offset(0,-1).setValue(e.range.offset(0,-1).getValue() + 1);
  }
  if(sh.getName()=='Sheet233' && e.range.columnStart==4) {
    e.source.toast('decr');
    e.range.setValue("FALSE");
    e.range.offset(0,-2).setValue(e.range.offset(0,-2).getValue() - 1);
  }
}

Animation:

enter image description here

Cooper
  • 59,616
  • 6
  • 23
  • 54