Created
April 23, 2024 13:12
-
-
Save woodwardtw/725c63ba9de0015900eb5fe25495f8c6 to your computer and use it in GitHub Desktop.
A Google script to dynamically change the data validation rules based on the selection from another cell.
This file contains 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 onEdit(){ | |
const ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
const entries = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("entries"); | |
const dropDowns = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("dropdowns"); | |
const activeCell = entries.getCurrentCell(); | |
const activity = activeCell.getValue(); | |
if(activeCell.getColumn() == 3 && activeCell.getRow() > 1){ | |
activeCell.offset(0,1).clearContent().clearDataValidations(); | |
if(activeCell.isBlank()) { | |
} | |
const dropDownValues = { | |
Conferences: "B2:B10", | |
Classes: "C2:C10", | |
Excursions: "D2:D10", | |
Tutoring: "E2:E10", | |
Workshops: "F2:F10" | |
}; | |
const rangeData = dropDownValues[activity];//frenchValues(dropDownValues,activity); | |
const getValueRange = dropDowns.getRange(rangeData) | |
const confValidationRule = SpreadsheetApp.newDataValidation().requireValueInRange(getValueRange).setAllowInvalid(false).build(); | |
activeCell.offset(0,1).setDataValidation(confValidationRule); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment