Michael Stromberg
Michael Stromberg

Reputation: 77

Google Sheets Apps Script onEdit() Trigger

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);
    }
  }
}

Upvotes: 2

Views: 9156

Answers (1)

Mogsdad
Mogsdad

Reputation: 45750

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.

Upvotes: 2

Related Questions