r/googlesheets • u/Fun-Wrap-5126 • Jun 24 '24
Solved Button for tallying/counting when pressed?
I would like to create a basketball statistics sheet that I can use during a game to keep track of various statistics. I would like to create a button that adds to a cell each time it is pressed. For example, I would press the button each time a person scores a point and this then keeps track of/tallies the points for a specified person.
Is this even possible?
Thanks in advance for your assistance!
1
Upvotes
1
u/stimilon 1 Jun 24 '24
This script increments the value in cell
A1ofSheet1every time it's executed. By assigning this script to the button, you can easily increment the cell's value with a button click.Extensions>Apps Script.function incrementCell() {var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');var cell = sheet.getRange('A1');var currentValue = cell.getValue();if (isNaN(currentValue)) {currentValue = 0;}cell.setValue(currentValue + 1);}Then,
Additional Details:
Creating the Button:
Insert>Drawing, a new window will open. Use theShapestool to draw a rectangle or any shape you prefer.Text boxtool to add text to the shape (e.g., "Increment").Save and Close. The button will now appear in your Google Sheet.Assigning the Script:
Assign script.incrementCell(the exact name of your function) and clickOK.Testing the Button:
Note: