Home > Mobile >  Custom Menu in UI - selection changes selection in drop down list
Custom Menu in UI - selection changes selection in drop down list

Time:05-17

I added a menu titled Reset Stats -> Inning Reset clicking this will change a few other items previously setup in my doc. I want the button to also change the selection of the dropdown menu to the number that is next in line. 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8

1 - Menu selection of "Inning Reset"

Selection Made "Inning Reset"


2 - All options available on the dropdown menu and I want the dropdown menu to select the following number. So right now 1 clicking the inning reset would go to 2, if it was 2 clicking inning reset would go to 3 and so on.

Selection Changes to the next number down


Dropdown menu changes to the next item in line.

Final Need

CodePudding user response:

Probably something like this?

function onOpen() {
  SpreadsheetApp.getUi().createMenu('Reset stats')
  .addItem('Inning Reset', 'inning_reset')
  .addToUi();
}

function inning_reset() {
  var cell = SpreadsheetApp.getActiveSheet().getRange('e3');
  var current_value = ''   cell.getValue(); // it should be a string!
  var dropdown_list = cell.getDataValidation().getCriteriaValues()[0];
  var next_index = dropdown_list.indexOf(current_value)   1;
  if (next_index == dropdown_list.length) next_index = 0; // cycle
  next_value = dropdown_list[next_index];
  cell.setValue(next_value);
}

Every click on the custom menu Inning Reset it changes a value in the cell E3 to the next value from its dropdown list: 1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 1 > 2 > 3 ... etc

  • Related