Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

How to start the script from the third row for dependent drop down list? [duplicate]

$
0
0

I am NOT expert in coding, just managed to piece together a script with dependent drop down list.The script is to allow user to select the drop down list from Row 1, Column B, C, D, ... (eg. B1) with dependent drop down list (eg. B2, B3, B4, B5). Similarly for Row 6, 11; Column B, C, D, ....However, the script doesn't work when I insert two rows above Row 1 as I would want the first and second row for date and time.

1

Below is the script that works if everything start from Row 1.

function onEdit() {  var tabLists = "Lists";  var tabValidation = "Main";  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();  var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabLists);  var activeCell = ss.getActiveCell();  if(activeCell.getRow() % 5 == 1 && activeCell.getColumn() > 1  && activeCell.getColumn() < 10  && ss.getSheetName() == tabValidation){    activeCell.offset(1, 0).clearContent().clearDataValidations();    activeCell.offset(2, 0).clearContent().clearDataValidations();    activeCell.offset(3, 0).clearContent().clearDataValidations();    activeCell.offset(4, 0).clearContent().clearDataValidations();    var makes = datass.getRange(1, 1, 1, datass.getLastColumn()).getValues();    var makeIndex = makes[0].indexOf(activeCell.getValue()) + 1;    if(makeIndex != 0){        var validationRange = datass.getRange(3, makeIndex, datass.getLastColumn());        var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();        activeCell.offset(1, 0).setDataValidation(validationRule);        activeCell.offset(2, 0).setDataValidation(validationRule);        activeCell.offset(3, 0).setDataValidation(validationRule);        activeCell.offset(4, 0).setDataValidation(validationRule);      }        }      }

Any advice on how to make it works if I would like to add two more rows above Row 1?


Viewing all articles
Browse latest Browse all 9782

Trending Articles