Last active
October 11, 2020 08:39
-
-
Save Max-Makhrov/24771146da8f9b3090bb32851b3eeeb4 to your computer and use it in GitHub Desktop.
2D Dependent Dropdown List. Max Makhrov
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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