2

I am new to programming, so bear with me here. I'm writing a script that, among other things, takes a cell value upon edit and then underlines a series of cells in various other ranges. The given cell has validation on it so that the user can only select from a range of options from a dropdown menu.

The validation function works fine from what I can tell, but when I edit the designated cell by selecting one of the dropdown menu options, nothing happens. Do I need to call the onEdit(e) function? I've read the api references and searched stackoverflow and the web for help, but I'm stuck.

Please advise; any help is appreciated. Here is the relevant part of my code:

function validateLeagueSizeInput(sheet) {
  var cell = sheet.getRange('G2'),
      values = [[8], [10], [12]],
      range = sheet.getRange('A998:A1000').setValues(values),
      rule = SpreadsheetApp.newDataValidation().requireValueInRange(range, true).build();
  cell.setDataValidation(rule);
}

function onEdit(e) {
  var cell = e.value,
      range = SpreadsheetApp.getActiveSheet().getRange('A2:F301');
  for (var i = cell + 1; i < Math.floor(301 / cell); i += cell) {
    for (var j = 1; j <= 6; j++) {
      range[i][j].setBorder(null, null, true, null, null, null);
    }
  }
}
  • 1
    "hard code" a value for the variable `cell` -> `var cell = 5;`. Then set a break point and run the debugger. [Link to Google Documentation - Troubleshooting](https://developers.google.com/apps-script/troubleshooting#using_the_debugger_and_breakpoints) Step through the code. If you are not sure if the `onEdit()` function is running, add a `Logger.log('it ran! ' + e.value);` statement at the top, edit a cell, then VIEW the LOGS. – Alan Wells Jul 01 '15 at 01:56
  • Thanks for the advice, @SandyGood! I had tried logging the `cell` variable previously, and the `onEdit(e)` function is definitely not being triggered. It could be that options selected from a drop down menu do not trigger the `onEdit()` function, as @Mogsdad has eluded. – Michael Stromberg Jul 01 '15 at 20:06
  • Try an installed change trigger event. – Alan Wells Jul 01 '15 at 20:09
  • Thanks again for the input. I decided to just create a menu item and have the code execute when triggered that way. – Michael Stromberg Jul 02 '15 at 22:52

1 Answers1

2

There are plenty of Spreadsheet changes that don't trigger onEdit() functions - you may just be the first person to report this particular one. See Detect user inserting row or column in a google spreadsheet and reacting in a script.

Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • Thanks for the information, @Mogsdad! Can you think of another way to trigger underlining code by allowing a user to only choose from a finite list of options? – Michael Stromberg Jul 01 '15 at 20:08
  • Thanks again for the input. I decided to just create a menu item and have the code execute when triggered that way. – Michael Stromberg Jul 02 '15 at 22:52