Skip to content

Instantly share code, notes, and snippets.

@Max-Makhrov
Last active October 11, 2020 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Max-Makhrov/24771146da8f9b3090bb32851b3eeeb4 to your computer and use it in GitHub Desktop.
Save Max-Makhrov/24771146da8f9b3090bb32851b3eeeb4 to your computer and use it in GitHub Desktop.
2D Dependent Dropdown List. Max Makhrov
function make2DDataValidation() {
// ............................... Settings ......................................
// Sheet names
var tsheet = 'Sheet1'; // The name of the work sheet with data validation
var dsheet = 'data'; // The name of the data sheet
// The data validation range:
var rownum = 1000; // The number of the last row of validation
var vcol = 2; // The number of a column to make validation
var vrow = 2; // The number of a row to start validation
// The range with conditions
var clen = 10; // The number of columns with conditions
var ccol = 6; // The number of a column with conditions
//................................................................................
for (var i = vrow; i <= rownum; i++) {
// Set the data validation
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName(tsheet);
var shData = ss.getSheetByName(dsheet);
var cell = sh.getRange(i, vcol, 1, 1);
var range = shData.getRange(i, ccol, 1, clen);
var rule = SpreadsheetApp.newDataValidation().requireValueInRange(range).build();
cell.setDataValidation(rule);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment