Google Script Button to increase value to specific rows and columns in Google Sheets











up vote
0
down vote

favorite












I am using Google Sheets with a series of buttons. I want to click the button to increase the value in a specific row.



For example:
When I click on "Player 1" button, it will go to Player 1 row, then when I click on the "Rebound" button, it will add a value of 1 in that cell. Then, if I click the "Steal" button, it will add value in Player 1's row, and under the "Steal" column. The same goes for all of the other "player" buttons. I am having trouble finding out how to do this. I want to create a basketball box score when I can score the game with button clicks. Thank you in advance.
enter image description here



Google Script:






function increment(){

// define the cell to be incremented
var cell = SpreadsheetApp.getActiveSheet().getRange("B2");

// get and set the cell value
var cellValue = cell.getValue();
cell.setValue(cellValue + 1); // this increments by 1 but could be any number

}





The Google Script that I have allows my to increase the value by one for cell B2 alone. I would like to be able to use the Player Buttons to select the row and the Rebound, Turnover, Steal button to select the column and add value. I am very new to coding and scripting. Sorry.










share|improve this question
























  • Provide your code and show off your research efforts
    – TheMaster
    Nov 7 at 17:22










  • Sorry for the vague question. I updated my information. I only found a way to add value to one cell using one button. I would like to use the Player buttons to select the row and the buttons on the right to select the column. Are you able to help with this? Thank you.
    – S.Clancy
    Nov 7 at 17:35






  • 1




    I would use a sidebar. It's easier to create the buttons and assign them to functions. That way you can pass parameters from the buttons to the function so that one function will work for all buttons. You also might want to check out how to use google.script.run.
    – Cooper
    Nov 7 at 19:07










  • Thank you @Cooper. I will take a look at that information. Would a sidebar be the most efficient way. I will have 12 "Player Buttons" and over 30 "Attribute" buttons. I do not know where to start to create what I am trying to create. Thank you.
    – S.Clancy
    Nov 7 at 19:18















up vote
0
down vote

favorite












I am using Google Sheets with a series of buttons. I want to click the button to increase the value in a specific row.



For example:
When I click on "Player 1" button, it will go to Player 1 row, then when I click on the "Rebound" button, it will add a value of 1 in that cell. Then, if I click the "Steal" button, it will add value in Player 1's row, and under the "Steal" column. The same goes for all of the other "player" buttons. I am having trouble finding out how to do this. I want to create a basketball box score when I can score the game with button clicks. Thank you in advance.
enter image description here



Google Script:






function increment(){

// define the cell to be incremented
var cell = SpreadsheetApp.getActiveSheet().getRange("B2");

// get and set the cell value
var cellValue = cell.getValue();
cell.setValue(cellValue + 1); // this increments by 1 but could be any number

}





The Google Script that I have allows my to increase the value by one for cell B2 alone. I would like to be able to use the Player Buttons to select the row and the Rebound, Turnover, Steal button to select the column and add value. I am very new to coding and scripting. Sorry.










share|improve this question
























  • Provide your code and show off your research efforts
    – TheMaster
    Nov 7 at 17:22










  • Sorry for the vague question. I updated my information. I only found a way to add value to one cell using one button. I would like to use the Player buttons to select the row and the buttons on the right to select the column. Are you able to help with this? Thank you.
    – S.Clancy
    Nov 7 at 17:35






  • 1




    I would use a sidebar. It's easier to create the buttons and assign them to functions. That way you can pass parameters from the buttons to the function so that one function will work for all buttons. You also might want to check out how to use google.script.run.
    – Cooper
    Nov 7 at 19:07










  • Thank you @Cooper. I will take a look at that information. Would a sidebar be the most efficient way. I will have 12 "Player Buttons" and over 30 "Attribute" buttons. I do not know where to start to create what I am trying to create. Thank you.
    – S.Clancy
    Nov 7 at 19:18













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using Google Sheets with a series of buttons. I want to click the button to increase the value in a specific row.



For example:
When I click on "Player 1" button, it will go to Player 1 row, then when I click on the "Rebound" button, it will add a value of 1 in that cell. Then, if I click the "Steal" button, it will add value in Player 1's row, and under the "Steal" column. The same goes for all of the other "player" buttons. I am having trouble finding out how to do this. I want to create a basketball box score when I can score the game with button clicks. Thank you in advance.
enter image description here



Google Script:






function increment(){

// define the cell to be incremented
var cell = SpreadsheetApp.getActiveSheet().getRange("B2");

// get and set the cell value
var cellValue = cell.getValue();
cell.setValue(cellValue + 1); // this increments by 1 but could be any number

}





The Google Script that I have allows my to increase the value by one for cell B2 alone. I would like to be able to use the Player Buttons to select the row and the Rebound, Turnover, Steal button to select the column and add value. I am very new to coding and scripting. Sorry.










share|improve this question















I am using Google Sheets with a series of buttons. I want to click the button to increase the value in a specific row.



For example:
When I click on "Player 1" button, it will go to Player 1 row, then when I click on the "Rebound" button, it will add a value of 1 in that cell. Then, if I click the "Steal" button, it will add value in Player 1's row, and under the "Steal" column. The same goes for all of the other "player" buttons. I am having trouble finding out how to do this. I want to create a basketball box score when I can score the game with button clicks. Thank you in advance.
enter image description here



Google Script:






function increment(){

// define the cell to be incremented
var cell = SpreadsheetApp.getActiveSheet().getRange("B2");

// get and set the cell value
var cellValue = cell.getValue();
cell.setValue(cellValue + 1); // this increments by 1 but could be any number

}





The Google Script that I have allows my to increase the value by one for cell B2 alone. I would like to be able to use the Player Buttons to select the row and the Rebound, Turnover, Steal button to select the column and add value. I am very new to coding and scripting. Sorry.






function increment(){

// define the cell to be incremented
var cell = SpreadsheetApp.getActiveSheet().getRange("B2");

// get and set the cell value
var cellValue = cell.getValue();
cell.setValue(cellValue + 1); // this increments by 1 but could be any number

}





function increment(){

// define the cell to be incremented
var cell = SpreadsheetApp.getActiveSheet().getRange("B2");

// get and set the cell value
var cellValue = cell.getValue();
cell.setValue(cellValue + 1); // this increments by 1 but could be any number

}






button google-apps-script google-sheets






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 17:33

























asked Nov 7 at 16:59









S.Clancy

335




335












  • Provide your code and show off your research efforts
    – TheMaster
    Nov 7 at 17:22










  • Sorry for the vague question. I updated my information. I only found a way to add value to one cell using one button. I would like to use the Player buttons to select the row and the buttons on the right to select the column. Are you able to help with this? Thank you.
    – S.Clancy
    Nov 7 at 17:35






  • 1




    I would use a sidebar. It's easier to create the buttons and assign them to functions. That way you can pass parameters from the buttons to the function so that one function will work for all buttons. You also might want to check out how to use google.script.run.
    – Cooper
    Nov 7 at 19:07










  • Thank you @Cooper. I will take a look at that information. Would a sidebar be the most efficient way. I will have 12 "Player Buttons" and over 30 "Attribute" buttons. I do not know where to start to create what I am trying to create. Thank you.
    – S.Clancy
    Nov 7 at 19:18


















  • Provide your code and show off your research efforts
    – TheMaster
    Nov 7 at 17:22










  • Sorry for the vague question. I updated my information. I only found a way to add value to one cell using one button. I would like to use the Player buttons to select the row and the buttons on the right to select the column. Are you able to help with this? Thank you.
    – S.Clancy
    Nov 7 at 17:35






  • 1




    I would use a sidebar. It's easier to create the buttons and assign them to functions. That way you can pass parameters from the buttons to the function so that one function will work for all buttons. You also might want to check out how to use google.script.run.
    – Cooper
    Nov 7 at 19:07










  • Thank you @Cooper. I will take a look at that information. Would a sidebar be the most efficient way. I will have 12 "Player Buttons" and over 30 "Attribute" buttons. I do not know where to start to create what I am trying to create. Thank you.
    – S.Clancy
    Nov 7 at 19:18
















Provide your code and show off your research efforts
– TheMaster
Nov 7 at 17:22




Provide your code and show off your research efforts
– TheMaster
Nov 7 at 17:22












Sorry for the vague question. I updated my information. I only found a way to add value to one cell using one button. I would like to use the Player buttons to select the row and the buttons on the right to select the column. Are you able to help with this? Thank you.
– S.Clancy
Nov 7 at 17:35




Sorry for the vague question. I updated my information. I only found a way to add value to one cell using one button. I would like to use the Player buttons to select the row and the buttons on the right to select the column. Are you able to help with this? Thank you.
– S.Clancy
Nov 7 at 17:35




1




1




I would use a sidebar. It's easier to create the buttons and assign them to functions. That way you can pass parameters from the buttons to the function so that one function will work for all buttons. You also might want to check out how to use google.script.run.
– Cooper
Nov 7 at 19:07




I would use a sidebar. It's easier to create the buttons and assign them to functions. That way you can pass parameters from the buttons to the function so that one function will work for all buttons. You also might want to check out how to use google.script.run.
– Cooper
Nov 7 at 19:07












Thank you @Cooper. I will take a look at that information. Would a sidebar be the most efficient way. I will have 12 "Player Buttons" and over 30 "Attribute" buttons. I do not know where to start to create what I am trying to create. Thank you.
– S.Clancy
Nov 7 at 19:18




Thank you @Cooper. I will take a look at that information. Would a sidebar be the most efficient way. I will have 12 "Player Buttons" and over 30 "Attribute" buttons. I do not know where to start to create what I am trying to create. Thank you.
– S.Clancy
Nov 7 at 19:18












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










There exists:




  1. An setActiveSelection function you could use to select a range of cells when a Player button is clicked, and

  2. A getSelection function you could use when an "event" button is pressed (rebound, turnover, or steal) to get the current selection and then select the correct portion of that.


Player Buttons



I think each of your player functions is going to have to call a custom function, ie, selectPlayerOneRange(), selectPlayerTwoRange(). Something like this:



var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

function selectPlayerOneRange() {
sheet.setActiveSelection("B2:D2");
}

function selectPlayerTwoRange() {
...


Action Buttons



Similarly, each of your action buttons will require their own script. I might do something like this:



function getSelectedRow() {
var sel = ss.getSelection();
var range = sel.getActiveRange();
var row = range.getRow();
return row;
}

function incrementRebound() {
var row = getSelectedRow();
var col = 2;
var cell = sheet.getRange(row, col);
// Your increment code here:
var cellValue = cell.getValue();
cell.setValue(cellValue + 1);
}

function incrementSteal() {
var row = getSelectedRow();
var col = 4;
...





share|improve this answer





















  • Thank you very much. That is the start that I needed. I was not familiar with how to go about and do it. Thank you once again.
    – S.Clancy
    Nov 8 at 1:23










  • You're welcome! I think this solves your problem and is relatively simple, but it is a bit cumbersome to write so many little custom functions. Using an HTML sidebar, as suggested in the comments, might be more elegant. You could have buttons that call a single function with an argument, (ie, selectPlayerRange(1) instead of selectPlayerOneRange().) See: developers.google.com/apps-script/guides/dialogs
    – Dustin Michels
    Nov 8 at 18:44













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194261%2fgoogle-script-button-to-increase-value-to-specific-rows-and-columns-in-google-sh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










There exists:




  1. An setActiveSelection function you could use to select a range of cells when a Player button is clicked, and

  2. A getSelection function you could use when an "event" button is pressed (rebound, turnover, or steal) to get the current selection and then select the correct portion of that.


Player Buttons



I think each of your player functions is going to have to call a custom function, ie, selectPlayerOneRange(), selectPlayerTwoRange(). Something like this:



var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

function selectPlayerOneRange() {
sheet.setActiveSelection("B2:D2");
}

function selectPlayerTwoRange() {
...


Action Buttons



Similarly, each of your action buttons will require their own script. I might do something like this:



function getSelectedRow() {
var sel = ss.getSelection();
var range = sel.getActiveRange();
var row = range.getRow();
return row;
}

function incrementRebound() {
var row = getSelectedRow();
var col = 2;
var cell = sheet.getRange(row, col);
// Your increment code here:
var cellValue = cell.getValue();
cell.setValue(cellValue + 1);
}

function incrementSteal() {
var row = getSelectedRow();
var col = 4;
...





share|improve this answer





















  • Thank you very much. That is the start that I needed. I was not familiar with how to go about and do it. Thank you once again.
    – S.Clancy
    Nov 8 at 1:23










  • You're welcome! I think this solves your problem and is relatively simple, but it is a bit cumbersome to write so many little custom functions. Using an HTML sidebar, as suggested in the comments, might be more elegant. You could have buttons that call a single function with an argument, (ie, selectPlayerRange(1) instead of selectPlayerOneRange().) See: developers.google.com/apps-script/guides/dialogs
    – Dustin Michels
    Nov 8 at 18:44

















up vote
1
down vote



accepted










There exists:




  1. An setActiveSelection function you could use to select a range of cells when a Player button is clicked, and

  2. A getSelection function you could use when an "event" button is pressed (rebound, turnover, or steal) to get the current selection and then select the correct portion of that.


Player Buttons



I think each of your player functions is going to have to call a custom function, ie, selectPlayerOneRange(), selectPlayerTwoRange(). Something like this:



var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

function selectPlayerOneRange() {
sheet.setActiveSelection("B2:D2");
}

function selectPlayerTwoRange() {
...


Action Buttons



Similarly, each of your action buttons will require their own script. I might do something like this:



function getSelectedRow() {
var sel = ss.getSelection();
var range = sel.getActiveRange();
var row = range.getRow();
return row;
}

function incrementRebound() {
var row = getSelectedRow();
var col = 2;
var cell = sheet.getRange(row, col);
// Your increment code here:
var cellValue = cell.getValue();
cell.setValue(cellValue + 1);
}

function incrementSteal() {
var row = getSelectedRow();
var col = 4;
...





share|improve this answer





















  • Thank you very much. That is the start that I needed. I was not familiar with how to go about and do it. Thank you once again.
    – S.Clancy
    Nov 8 at 1:23










  • You're welcome! I think this solves your problem and is relatively simple, but it is a bit cumbersome to write so many little custom functions. Using an HTML sidebar, as suggested in the comments, might be more elegant. You could have buttons that call a single function with an argument, (ie, selectPlayerRange(1) instead of selectPlayerOneRange().) See: developers.google.com/apps-script/guides/dialogs
    – Dustin Michels
    Nov 8 at 18:44















up vote
1
down vote



accepted







up vote
1
down vote



accepted






There exists:




  1. An setActiveSelection function you could use to select a range of cells when a Player button is clicked, and

  2. A getSelection function you could use when an "event" button is pressed (rebound, turnover, or steal) to get the current selection and then select the correct portion of that.


Player Buttons



I think each of your player functions is going to have to call a custom function, ie, selectPlayerOneRange(), selectPlayerTwoRange(). Something like this:



var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

function selectPlayerOneRange() {
sheet.setActiveSelection("B2:D2");
}

function selectPlayerTwoRange() {
...


Action Buttons



Similarly, each of your action buttons will require their own script. I might do something like this:



function getSelectedRow() {
var sel = ss.getSelection();
var range = sel.getActiveRange();
var row = range.getRow();
return row;
}

function incrementRebound() {
var row = getSelectedRow();
var col = 2;
var cell = sheet.getRange(row, col);
// Your increment code here:
var cellValue = cell.getValue();
cell.setValue(cellValue + 1);
}

function incrementSteal() {
var row = getSelectedRow();
var col = 4;
...





share|improve this answer












There exists:




  1. An setActiveSelection function you could use to select a range of cells when a Player button is clicked, and

  2. A getSelection function you could use when an "event" button is pressed (rebound, turnover, or steal) to get the current selection and then select the correct portion of that.


Player Buttons



I think each of your player functions is going to have to call a custom function, ie, selectPlayerOneRange(), selectPlayerTwoRange(). Something like this:



var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

function selectPlayerOneRange() {
sheet.setActiveSelection("B2:D2");
}

function selectPlayerTwoRange() {
...


Action Buttons



Similarly, each of your action buttons will require their own script. I might do something like this:



function getSelectedRow() {
var sel = ss.getSelection();
var range = sel.getActiveRange();
var row = range.getRow();
return row;
}

function incrementRebound() {
var row = getSelectedRow();
var col = 2;
var cell = sheet.getRange(row, col);
// Your increment code here:
var cellValue = cell.getValue();
cell.setValue(cellValue + 1);
}

function incrementSteal() {
var row = getSelectedRow();
var col = 4;
...






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 7 at 19:25









Dustin Michels

19513




19513












  • Thank you very much. That is the start that I needed. I was not familiar with how to go about and do it. Thank you once again.
    – S.Clancy
    Nov 8 at 1:23










  • You're welcome! I think this solves your problem and is relatively simple, but it is a bit cumbersome to write so many little custom functions. Using an HTML sidebar, as suggested in the comments, might be more elegant. You could have buttons that call a single function with an argument, (ie, selectPlayerRange(1) instead of selectPlayerOneRange().) See: developers.google.com/apps-script/guides/dialogs
    – Dustin Michels
    Nov 8 at 18:44




















  • Thank you very much. That is the start that I needed. I was not familiar with how to go about and do it. Thank you once again.
    – S.Clancy
    Nov 8 at 1:23










  • You're welcome! I think this solves your problem and is relatively simple, but it is a bit cumbersome to write so many little custom functions. Using an HTML sidebar, as suggested in the comments, might be more elegant. You could have buttons that call a single function with an argument, (ie, selectPlayerRange(1) instead of selectPlayerOneRange().) See: developers.google.com/apps-script/guides/dialogs
    – Dustin Michels
    Nov 8 at 18:44


















Thank you very much. That is the start that I needed. I was not familiar with how to go about and do it. Thank you once again.
– S.Clancy
Nov 8 at 1:23




Thank you very much. That is the start that I needed. I was not familiar with how to go about and do it. Thank you once again.
– S.Clancy
Nov 8 at 1:23












You're welcome! I think this solves your problem and is relatively simple, but it is a bit cumbersome to write so many little custom functions. Using an HTML sidebar, as suggested in the comments, might be more elegant. You could have buttons that call a single function with an argument, (ie, selectPlayerRange(1) instead of selectPlayerOneRange().) See: developers.google.com/apps-script/guides/dialogs
– Dustin Michels
Nov 8 at 18:44






You're welcome! I think this solves your problem and is relatively simple, but it is a bit cumbersome to write so many little custom functions. Using an HTML sidebar, as suggested in the comments, might be more elegant. You could have buttons that call a single function with an argument, (ie, selectPlayerRange(1) instead of selectPlayerOneRange().) See: developers.google.com/apps-script/guides/dialogs
– Dustin Michels
Nov 8 at 18:44




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194261%2fgoogle-script-button-to-increase-value-to-specific-rows-and-columns-in-google-sh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini