Skip to content

Instantly share code, notes, and snippets.

@DuaneNielsen
Last active August 7, 2025 05:48
Show Gist options
  • Select an option

  • Save DuaneNielsen/38a1ecacc1884a7d7634131c6c6abd61 to your computer and use it in GitHub Desktop.

Select an option

Save DuaneNielsen/38a1ecacc1884a7d7634131c6c6abd61 to your computer and use it in GitHub Desktop.
Droplist For GSheets
function convertToDropdowns() {
// Get the selected range
var range = SpreadsheetApp.getActiveRange();
var values = range.getValues();
// Loop through each cell in the selection
for (var i = 0; i < values.length; i++) {
for (var j = 0; j < values[i].length; j++) {
var cellValue = values[i][j];
// If cell has content
if (cellValue) {
// Split by semicolon and clean up
var items = cellValue.toString().split(';').map(function(item) {
return item.trim();
});
// Skip if only one item (no comma)
if (items.length === 1) {
continue;
}
// Get the cell
var cell = range.getCell(i + 1, j + 1);
// Create dropdown
var rule = SpreadsheetApp.newDataValidation()
.requireValueInList(items)
.setAllowInvalid(true) // This allows the current value to remain
.build();
cell.setDataValidation(rule);
// Clear the cell value
cell.setValue('');
// Or set to first item (uncomment if you prefer this)
// cell.setValue(items[0]);
}
}
}
}
// Add menu
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Dropdowns')
.addItem('Convert to Dropdowns', 'convertToDropdowns')
.addToUi();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment