I am trying to create a dependent drop down in my sheet that in Col A will allow you to select a list of regions (e.g. Americas, Africa, Asia) etc and then in Col B will show a list of the countries in the region selected in Col A.
I have tried using an =indirect and =index/match formula but they do not work for the totality of my sheet, which is over 1000 rows.
There are 11 tabs in my workbook, however I only want to pull data from the 'countries' tab in to the 'Master Calls Sheet' tab for validation. All the other tabs are =filter cuts from the main sheet.
In the countries tab, I have listed the regions in Col A from Row 2, with the corresponding countries in Col B, so it reads like:
Africa . Ghana Asia . Japan
and so on.
In my Master Calls tab, I have slicers etc at the top, so the data entry only starts from row 9.
I have attempted the script below, to no avail:
var mainWsName = "Master Calls Sheet";
var optionsWsName = "countries";
var firstLevelColumn = 1;
var secondLevelColumn = 2;
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("mainWsName");
var wsOptions = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("optionsWsName");
var options = wsOptions.getRange(2, 1,wsOptions.getLastRow()-1,2).getValues();
function myFunction() {
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 === firstLevelColumn && r > 8){
var filteredOptions = options.filter(function(o){ return o[0] === val });
var listToApply = filteredOptions.map(function(o){ return o[1] });
var cell = ws.getRange(r, 2);
applyValidationToCell(listToApply,cell)
}
}}
function applyValidationToCell(list,cell){
var rule = SpreadsheetApp
.newDataValidation()
.requireValueInList(list)
.setAllowInvalid(false)
.build;
cell.setDataValidation(rule)
}
Can anyone help?!?