Skip to content

Instantly share code, notes, and snippets.

@aldrincab
Created January 9, 2023 10:59
Show Gist options
  • Save aldrincab/311595c3afc6fef7f37bfa42051e220c to your computer and use it in GitHub Desktop.
Save aldrincab/311595c3afc6fef7f37bfa42051e220c to your computer and use it in GitHub Desktop.
Hello, I am new to this and I found an old post with this code. I am currently using it but it affects all tabs of my spreadsheet. Is there a way for it to work on a specific tab only? Thank you.
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment