Last active
June 27, 2023 15:37
-
-
Save sschwartzman/ed34dec66231acd9092051170d0ed6dc to your computer and use it in GitHub Desktop.
Create a Multi-Select Drop-Down for any cell in Google Sheets
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
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); | |
} | |
} | |
} |
Hello sir, just a question. How should the code go if you only want this to work on a specific tab? Thank you
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?
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
Based on https://spreadsheetpoint.com/multiple-selection-drop-down-google-sheets/
Improvements: