When I type "product" in a cell. The cell next to it would show a list of available variations via a drop-down menu?
Something like this? This is the data sheet
DATA SHEET:
Column A | Column B | Column C |
---|---|---|
Cell 1 | Products | Variation |
Cell 2 | Robot | Blue |
Cell 3 | Soldier | Yellow |
Cell 4 | Robot | Green |
When I type "product" in a cell. The cell next to it would show a list of available variations via a drop-down menu?
Something like this? This is the data sheet
DATA SHEET:
Column A | Column B | Column C |
---|---|---|
Cell 1 | Products | Variation |
Cell 2 | Robot | Blue |
Cell 3 | Soldier | Yellow |
Cell 4 | Robot | Green |
And I was hoping to do something like this When I type "ROBOT" in a cell. The cell next to it would limit my choices/data validation or filter the choices/data validation to only the "Variation" under Robot.
NEW SHEET:
Column A | Column B | Column C |
---|---|---|
Cell 1 | Products | Variation |
Cell 2 | I type ROBOT here | The choices for available variation appears here |
Would it be possible?
Share Improve this question edited Mar 24 at 3:49 Alma_Matters 1,0061 gold badge2 silver badges13 bronze badges asked Mar 18 at 5:25 Jenn PomonaJenn Pomona 1 3 |1 Answer
Reset to default 2Create a drop down of variations for a product
You can achieve this using Google Apps Script, Inserting a value from DATA SHEET
to NEW SHEET
and creating a drop-down in the next cell in any cell.
Script Used
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var targetSheetName = "NEW SHEET";
var dataSheetName = "DATA SHEET";
if (sheet.getName() !== targetSheetName) {
return;
}
var editedCell = e.range;
var product = editedCell.getValue().toString().toLowerCase();
var nextColumn = editedCell.getColumn() + 1;
if (editedCell.getRow() === 1) {
return;
}
var dataSheet = e.source.getSheetByName(dataSheetName);
var dataRange = dataSheet.getDataRange().getValues();
var variations = [];
for (var i = 1; i < dataRange.length; i++) {
if (dataRange[i][0].toString().toLowerCase() === product) {
variations.push(dataRange[i][1]);
}
}
var validationRange = sheet.getRange(editedCell.getRow(), nextColumn);
if (variations.length > 0) {
var rule = SpreadsheetApp.newDataValidation()
.requireValueInList(variations, true)
.build();
validationRange.setDataValidation(rule);
} else {
validationRange.setDataValidation(null);
}
}
Sample Output
DATA SHEET | |
---|---|
Robot | Blue |
Robot | Green |
Soldier | Yellow |
Robot | Red |
References
Data Validation
Event Object
```
) so your example table is at least legible. – Stelio Kontos Commented Mar 18 at 21:36