I am trying to setup dynamic, dependent, dropdown data validation lists. The intent is that when I select an item from a list in column A, the dropdown list in column B will be changed automatically to reflect possible options.
Even though I am new to coding, I have managed to get this part working on the sheet I want.
However, when I make any change on another sheet, well, it also makes changes to that other sheet. I need this script to work on only 1 sheet and can't figure out how.
It seems people have been running in similar issues here, but I haven't been able to adapt their solutions to my situation.
I have also tried also to replace the getActiveSheet by getSheetByName with the sheet i want changed but it doesn't seem to work.
function onEdit() {
var activecell = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveCell();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sectors");
if(activecell.getColumn() == 3 && activecell.getRow() >1 ) {
activecell.offset(0, 1).clearContent().clearDataValidations();
if(activecell.isBlank()){
}
var sector1 = datass.getRange(1, 1, 1, datass.getLastColumn()).getValues();
var sector1Index = sector1[0].indexOf(activecell.getValue()) +1 ;
var validationRange1 = datass.getRange(2, sector1Index, 25);
var validationRule1 = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange1);
activecell.offset(0, 1).setDataValidation(validationRule1)
}
}
when I make any change on another sheet, well, it also makes changes to that other sheet. I need this script to work on only 1 sheet and can't figure out how.
Thank you