Skip to content

Instantly share code, notes, and snippets.

@sschwartzman
Last active June 27, 2023 15:37
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sschwartzman/ed34dec66231acd9092051170d0ed6dc to your computer and use it in GitHub Desktop.
Save sschwartzman/ed34dec66231acd9092051170d0ed6dc to your computer and use it in GitHub Desktop.
Create a Multi-Select Drop-Down for any cell in Google Sheets
const separator = ', ';
const dvType = SpreadsheetApp.DataValidationCriteria.VALUE_IN_RANGE;
function onEdit(e) {
if (e.value != null && e.oldValue != null && e.value !== "") {
var dataValidation = e.range.getDataValidation();
if(dataValidation != null && dataValidation.getCriteriaType() == dvType &&
e.value.indexOf(separator) < 0 && e.oldValue.indexOf(e.value) < 0) {
e.range.setValue(e.oldValue + separator + e.value);
}
}
}
@is-rubes
Copy link

I got the following error

TypeError: Cannot read properties of undefined (reading 'value')
onEdit @ Code.gs:4

does this have something to do with validating e.value and e.oldValue? how do I do that?

@play150
Copy link

play150 commented Jun 27, 2023

I have the same error! :c

edit: i realized that it throws the error in the AppScript editor, but it's executing the script when I make edits in the spreadsheet (based on the execution history). However, it still doesn't seem to be doing anything on the sheet (the original script from spreadsheetpoint is working though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment