Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9628

Clear DropDown when Cell is cleared

$
0
0

with the help of a tutorial i made a script with dependent drop downs. I tried to modify it that when a cell in Column A is cleared/modified the first level of the drop down too.

var mainWsName = "master";var optionsWsName = "options";var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(mainWsName);var wsOptions = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(optionsWsName);var options = wsOptions.getRange(2, 1,wsOptions.getLastRow()-1,2).getValues();function onEdit(e){  var activeCell = e.range;  var val = activeCell.getValue();  var r = activeCell.getRow();  var c = activeCell.getColumn();  var wsName = activeCell.getSheet().getName();  if(wsName == mainWsName && c == 2 && r > 3){    if(val === ""){      ws.getRange(r, 3).clearContent();       ws.getRange(r, 3).clearDataValidations();    } else {      ws.getRange(r, 3).clearContent();       var filteredOptions = options.filter(function(o){ return o[0] === val });      var listToApply = filteredOptions.map(function(o){ return o[1] });      var cell = ws.getRange(r, 3);       applyValidationToCell(listToApply,cell);    }  }  }function applyValidationToCell(list,cell){  var rule = SpreadsheetApp  .newDataValidation()  .requireValueInList(list)  .setAllowInvalid(false)  .build();  cell.setDataValidation(rule);}

Viewing all articles
Browse latest Browse all 9628

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>