Last active
August 7, 2025 05:48
-
-
Save DuaneNielsen/38a1ecacc1884a7d7634131c6c6abd61 to your computer and use it in GitHub Desktop.
Droplist For GSheets
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
| 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