Alex
Alex

Reputation: 11

Trying to add multiple different increment functions to google sheet via appscript

So I have followed instructions from multiple posts to create an AppsScript function that allows me to tally votes for responses in a shared google sheet. I am trying to create a collaborative form where employees can submit their feedback, and then instead of having multiples of that feedback additional employees who agree can click a button where it tallies the number of 'votes' that feedback has received.

I have gotten this to work for one row, but how do I use multiple 'increment' functions in the same sheet? Each function would represent responses from a different row, but as you probably know when you are selecting which function to attach to a button (drawing) you are only able to insert the name of the function, which would be the same 'increment' even though the functions are written differently...

Unfortunately I can't share the document because it is hosted on my work platform and I am unable to share it to the public.

Here is what I am working with- essentially I want to have multiple "Agree" buttons with the function representing only that row.

This is the code I have been using:

function increment() {
  SpreadsheetApp
    .getActiveSheet()
    .getRange('C5')
    .setValue(SpreadsheetApp.getActiveSheet().getRange('C5').getValue() + 1);
}

And the code would change to C6, C7, etc. for each row.

I have tried adding each increment code for every row in appscript and it will only tally in the last row. I have tried making separate increment codes on different tabs and it does the same thing.

Please help I have spend hours looking for a response and nothing has helped! google sheet layout

Upvotes: 0

Views: 215

Answers (1)

Alex
Alex

Reputation: 11

I figured it out!

By writing my own custom function I was able to create this code but change the custom name to match each row number, and assign each button the correct code name matching with that number.

Here is a copy-able version of the Google Doc: https://docs.google.com/spreadsheets/d/12w_Rymf02Bnfi2dnHBiZjLuMV9YOkZ4qtHeSg7grYZc/edit?usp=sharing

And a link to the web app for the appscript if it for some reason doesn't transfer with the sheet (I also linked it in the sheet as well) https://script.google.com/macros/s/AKfycbxE1mL5VKeEGosfS74yzzK2g1WZ6aOj2kdamcwkrIynVPAq38Q/exec

And here is my actual coded functions that are applicable to this sheet although it can be modified for your individual needs:

function vote5() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C5')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C5').getValue() + 1);
}
function vote6() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C6')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C6').getValue() + 1);
}
function vote7() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C7')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C7').getValue() + 1);
}
function vote8() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C8')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C8').getValue() + 1);
}
function vote9() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C9')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C9').getValue() + 1);
}
function vote10() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C10')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C10').getValue() + 1);
}
function vote11() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C11')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C11').getValue() + 1);
}
function vote12() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C12')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C12').getValue() + 1);
}
function vote13() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C13')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C13').getValue() + 1);
}
function vote14() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C14')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C14').getValue() + 1);
}
function vote15() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C15')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C15').getValue() + 1);
}
function vote16() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C16')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C16').getValue() + 1);
}
function vote17() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C17')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C17').getValue() + 1);
}
function vote18() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C18')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C18').getValue() + 1);
}
function vote19() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C19')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C19').getValue() + 1);
}
function vote20() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C20')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C20').getValue() + 1);
}
function vote21() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C21')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C21').getValue() + 1);
}
function vote22() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C22')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C22').getValue() + 1);
}
function vote23() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C23')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C23').getValue() + 1);
}
function vote24() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C24')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C24').getValue() + 1);
}
function vote25() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C25')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C25').getValue() + 1);
}
function vote26() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C26')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C26').getValue() + 1);
}
function vote27() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C27')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C27').getValue() + 1);
}
function vote28() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C28')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C28').getValue() + 1);
}
function vote29() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C29')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C29').getValue() + 1);
}
function vote30() {
  SpreadsheetApp
  .getActiveSheet()
  .getRange('C30')
  .setValue(SpreadsheetApp.getActiveSheet().getRange('C30').getValue() + 1);
}

Upvotes: 1

Related Questions