If I understand you correctly, you want to create a dropdown in each cell in column B whose options are integers that go from 0 to the corresponding Stock Quantity in column C.
If that's the case, you can copy the following function to the script bound to your spreadsheet:
function generateDropdowns() {
var ss = SpreadsheetApp.getActive(); // Get the spreadsheet bound to this script
var sheet = ss.getSheetByName("Working with script"); // Get the sheet called "Working with script" (change if necessary)
// Get the different values in column C (stock quantities):
var firstRow = 2;
var firstCol = 3;
var numRows = sheet.getLastRow() - firstRow + 1;
var stockQuantities = sheet.getRange(firstRow, firstCol, numRows).getValues();
// Iterate through all values in volumn:
for (var i = 0; i < stockQuantities.length; i++) {
var stockQuantity = stockQuantities[i][0];
var values = [];
// Create the different options for the dropdown based on the value in column C:
for (var j = 0; j <= stockQuantity; j++) {
values.push(j);
}
// Create the data validation:
var rule = SpreadsheetApp.newDataValidation().requireValueInList(values).build();
// Add the data validation to the corresponding cell in column B:
var dropdownCell = sheet.getRange(i + firstRow, 2).setDataValidation(rule);
}
}
This script does the following (check inline comments for more detailed information):
I hope this is of any help.
Stock Quantitiesin column F, considering that the are many more items there than there are dropdowns? Also, how to track which dropdowns should modify which Stock Quantities? Please consider making all this clear so that people can help you. - Iamblichus