I combined the scripts to operate the two onedits. But only onedit1 works, and onedit2 doesn't work
I don't know which part I need to fix to make both of them work.
Should I add something to the onedit part? Or which part should I exclude?
function onEdit(e){
onedit1(e);
onedit2(e)
}
function onedit1(e){
var tabLists = "lists1";
var tabValidation = "Questions_B";
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabLists);
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 4 && activeCell.getRow() > 1 && ss.getSheetName() == tabValidation){
activeCell.offset(0, 1).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.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
function onedit2(e){
var tabLists = "lists2";
var tabValidation = "Questions_R";
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabLists);
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 4 && activeCell.getRow() > 1 && ss.getSheetName() == tabValidation){
activeCell.offset(0, 1).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.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
}
}
}
}
}
}
You have defined onedit2 inside onedit1 but you never execute it. You only define it.
If you want to keep the two onEdit function apart then simply separate them so they can both be executed by the main onEdit:
function onEdit(e){
onedit1(e);
onedit2(e);
}
// onedit1
function onedit1(e){
var tabLists = "lists1";
var tabValidation = "Questions_B";
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabLists);
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 4 && activeCell.getRow() > 1 && ss.getSheetName() == tabValidation){
activeCell.offset(0, 1).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.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
}
}
}
// onedit2
function onedit2(e){
var tabLists = "lists2";
var tabValidation = "Questions_R";
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabLists);
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 4 && activeCell.getRow() > 1 && ss.getSheetName() == tabValidation){
activeCell.offset(0, 1).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.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
}
}
}
Related
I've been trying to make dependent drop down lists using App script. When I select my independent drop down option, executions shows "Completed", yet it won't add in the dependent drop down in the column beside it.
I can't seem to figure out what's going wrong here:
function onEdit(){
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Exercise Index");
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 1 && activeCell.getRow() > 3 && ss.getSheetName()=="Weekly Template"){
activeCell.offset(0,1).clearContent().clearDataValidations();
var categories = datass.getRange(1,1,1,datass.getLastColumn()).getValues();
var catIndex = categories[0].indexOf(activeCell.getValue())+1;
if(catIndex != 0){
var validationRange = datass.getRange(2,catIndex,datass.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0,1).setDataValidation(validationRule);
}
}
}
Any help would be greatly appreciated as this is my first go at App Script.
I did manage to get it functioning as intended. Here's the script in case anyone comes across this in the future:
function onEdit(){
var tabLists = "Exercise Index";
var spreadsheet = SpreadsheetApp;
var activeSheet = spreadsheet.getActiveSpreadsheet().getActiveSheet();
var data = spreadsheet.getActiveSpreadsheet().getSheetByName(tabLists);
var activeCell = activeSheet.getActiveCell();
if(activeCell.getColumn() == 1 && activeCell.getRow() > 3 && activeSheet.getSheetName().includes("Week")){
activeCell.offset(0, 1).clearDataValidations();
var makes = data.getRange(1, 1, 1, data.getLastColumn()).getValues();
var makeIndex = makes[0].indexOf(activeCell.getValue()) + 1;
if(makeIndex != 0){
var validationRange = data.getRange(2, makeIndex, data.getLastRow());
var validationRule = spreadsheet.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
}
}
}
I have one workbook with multiple sheets and I've been running some simple scripts on two of those sheets (those sheets are basically copies of one another).
Once script creates a dropdown based on the value entered in one of the cells, while the second script adds a timestamp based on when the new dropdown was edited.
Initially I had two onEdit functions running on the first sheet.
Then I created a copy of these functions, with small amendments, to run on another sheet(same workbook)
Given that I don't really know how to have a separate script per worksheet I now have a one script with 4 similar onEdit functions.
Since I'm a total newbie I'm sure there's a better, more efficient way to write this code.
I'd appreciate your help in optimizing this.
function onEdit(e) {
addTimestamp(e);
addTimestamp2(e);
Dropdown(e);
Dropdown2(e);
}
function addTimestamp(e) {
var startRow = 2;
var targetColumn = 10;
var ws = "Tracker1";
var row = e.range.get.Row();
var col = e.range.getColumn();
if(col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws) {
var currentDate = new Date();
e.source.getActiveSheet().getRange(row,11).setValue(currentDate);
}
}
function addTimestamp2(e) {
var startRow = 2;
var targetColumn = 10;
var ws = "Tracker2";
var row = e.range.get.Row();
var col = e.range.getColumn();
if(col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws) {
var currentDate = new Date();
e.source.getActiveSheet().getRange(row,11).setValue(currentDate);
}
}
function Dropdown(){
var tabLists = "StatusFlow";
var tabValidation = "Tracker1"
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabLists);
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 9 && activeCell.getRow() > 1 && ss.getSheetName() == tabValidation){
activeCell.offset(o,1).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(2, makeIndex, datass.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).setAllowInvalid(false).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
}
}
}
function Dropdown2(){
var tabLists = "StatusFlow";
var tabValidation = "Tracker2"
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabLists);
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 9 && activeCell.getRow() > 1 && ss.getSheetName() == tabValidation){
activeCell.offset(o,1).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(2, makeIndex, datass.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).setAllowInvalid(false).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
}
}
}
here is a more efficient way to replace the two addTimestamp functions:
function onEdit(e) {
var activeSheet = e.source.getActiveSheet();
var activeSName = activeSheet.getName();
var row = e.range.get.Row();
var col = e.range.getColumn();
if ((activeSName == 'Tracker1' || activeSName == 'Tracker2') && col === 10 && row >= 2) {
activeSheet.getRange(row, 11).setValue(new Date());
}
}
You could give the two Dropdown functions a shot and see if you can do something similar. Nothing like learning-by-doing. :-D
Just be careful that in onEdit you are passing e to these Dropdown functions. But not using them in these functions.
This question already has an answer here:
Merging or Combining two onEdit trigger functions
(1 answer)
Closed 2 years ago.
I made a dependent drop-down with a script.
I'd like to apply it to two sheets.
but only OnEdit1 works and onEdit2 doesn't work.
I don't know what to do with both sheets.
Do I have to add or do something to make two sheets work?
function onEdit(e){
oneEdit1(e);
var tabLists = "lists";
var tabValidation = "Question_B";
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabLists);
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 4 && activeCell.getRow() > 1 && ss.getSheetName() == tabValidation){
activeCell.offset(0, 1).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.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
}
}
oneEdit2(e);
var tabListss = "lists2";
var tabValidations = "Qeustion_R";
var sss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datasss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabListss);
var activeCell = sss.getActiveCell();
if(activeCell.getColumn() == 4 && activeCell.getRow() > 1 && ss.getSheetName() == tabValidations){
activeCell.offset(0, 1).clearContent().clearDataValidations();
var makess = datasss.getRange(1, 1, 1, datasss.getLastColumn()).getValues();
var makeIndexs = makess[0].indexOf(activeCell.getValue()) + 1;
if(makeIndex != 0){
var validationRange = datasss.getRange(3, makeIndexs, datasss.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
}
}
}
Two combine two onEdit functions in one:
define both of them outside of the main function
call them from the main function
Sample:
function onEdit(e){
oneEdit1(e);
oneEdit2(e)
}
function oneEdit1(e){
...
}
function oneEdit2(e){
...
}
trying to get a script to only run on one tab, rather than impact all tabs - this one seems to be having an impact across multiple tabs for some reason.
Have tried declaring the name of the tab, which in this case would be:
"1. Scheduling"
but it breaks down and I get errors when trying to run the script. Any ideas?
function onEdit(){
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("3. Current_Team")
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 4 && activeCell.getRow() > 1){
activeCell.offset(0, 1).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.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
}
}
}
Try this:
function onEdit(e){
var sh=e.range.getSheet();
if(sh.getName()!='1. Scheduling')return;
var datash=e.source.getSheetByName("3. Current_Team")
if(e.range.columnStart==4 && e.range.rowStart>1){
e.range.offset(0, 1).clearContent().clearDataValidations();
var makes=datash.getRange(1, 1, 1, datash.getLastColumn()).getValues();
var makeIndex=makes[0].indexOf(e.value) + 1;
if(makeIndex != 0) {
var validationRange = datash.getRange(3, makeIndex, datash.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
e.range.offset(0, 1).setDataValidation(validationRule);
}
}
}
I asked this question the other day "Use GAS to search col A and return values of col B when matching" and received an answer which works perfectly!
But now I'm trying to modify the code to compare all of the previously selected column values and return the next value (B-E). So after projectTasksAdj!B5 is selected, the values from projectTasks!A5:B5 will be used to populate the data validation of projectTasksAdj!C5 and so on until projectTasksAdj!E5.
I only asked for the last process A & B & C & D though because I figured I could just trim it down myself as needed.
Here's a link to my sheet.
Here is my current script
function projectTasksAdjDV(e) {
var ptaSh=SpreadsheetApp.getActive().getSheetByName('projectTasksAdj');
var ptSh=SpreadsheetApp.getActive().getSheetByName('projectTasks');
var foundValues = [];
var foundValues2 = [];
var foundValues3 = [];
var activeCell = ptaSh.getActiveCell();
const valueToFind = activeCell.getValue();
if(activeCell.getColumn()==1 && activeCell.getRow() > 1){
activeCell.offset(0, 1).clearDataValidations();
var data=ptSh.getRange(3,1,ptaSh.getLastRow(),2).getValues(); // changed ptaSht
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][0]) {
foundValues.push(data[i][1]);
}
}
var colBValidationRange = foundValues;
var colBValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colBValidationRange).build();
activeCell.offset(0, 1).setDataValidation(colBValidationRule);
}
// Populate column C, D & E data validations
Logger.log("getColumn = " + activeCell.getColumn());
Logger.log("getRow = " + activeCell.getRow());
if(activeCell.getColumn() > 1 && activeCell.getColumn()<4 && activeCell.getRow()>1){
Logger.log("Row > 1 && Column < 4");
activeCell.offset(0, 1).clearDataValidations();
activeCell.offset(0, 2).clearDataValidations();
activeCell.offset(0, 3).clearDataValidations();
var ptadata=ptaSh.getRange(3,1,ptaSh.getLastRow(),5).getValues();
var ptdata=ptSh.getRange(3,4,ptSh.getLastRow(),5).getValues();
for(var i=0;i<ptadata.length;i++) {
if(valueToFind==ptadata[i][0]) {
foundValues.push(ptdata[i][0]);
}
Logger.log("foundValues = " + foundValues);
if(valueToFind==ptadata[i][1]) {
foundValues2.push(ptdata[i][0]);
}
Logger.log("foundValues2 = " + foundValues2);
if(valueToFind==ptadata[i][2]) {
foundValues3.push(ptdata[i][0]);
}
Logger.log("foundValues3 = " + foundValues3);
}
var colCValidationRange = foundValues;
var colCValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colCValidationRange).build();
activeCell.offset(0, 1).setDataValidation(colCValidationRule);
var colDValidationRange = foundValues2;
var colDValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colDValidationRange).build();
activeCell.offset(0, 2).setDataValidation(colDValidationRule);
var colEValidationRange = foundValues3;
var colEValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colEValidationRange).build();
activeCell.offset(0, 3).setDataValidation(colEValidationRule);
}
}
I noticed this in your code if(activeCell.getColumn() != 0){ and it is always true for any active cell.
function projectTasksAdjDV(e) {
var ptaSh=SpreadsheetApp.getActive().getSheetByName('projectTasksAdj');
var ptSh=SpreadsheetApp.getActive().getSheetByName('projectTasks');
var foundValues = [];
var foundValues2 = [];
var foundValues3 = [];
var activeCell = ptaSh.getActiveCell();
const valueToFind = activeCell.getValue();
if(activeCell.getColumn()==1 && activeCell.getRow() > 1){
activeCell.offset(0, 1).clearDataValidations();
var data=ptaSh.getRange(3,1,ptaSht.getLastRow(),2).getValues();
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][0]) {
foundValues.push(data[i][1]);
}
}
var colBValidationRange = foundValues;
var colBValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colBValidationRange).build();
activeCell.offset(0, 1).setDataValidation(colBValidationRule);
}
// Populate column C, D & E data validations
if(activeCell.getColumn()>0 && activeCell.getColumn()<4 && activeCell.getRow()>1){
activeCell.offset(0, 1).clearDataValidations();
activeCell.offset(0, 2).clearDataValidations();
activeCell.offset(0, 3).clearDataValidations();
var ptadata=ptaSh.getRange(3,1,ptaSh.getLastRow(),3).getValues();
var ptdata=ptSh.getRange(3,4,ptSh.getLastRow(),1).getValues();
for(var i=0;i<ptadata.length;i++) {
if(valueToFind==ptadata[i][0]) {
foundValues.push(ptdata[i][0]);
}
if(valueToFind==ptadata[i][1]) {
foundValues2.push(ptdata[i][0]);
}
if(valueToFind==ptadata[i][2]) {
foundValues3.push(ptdata[i][0]);
}
}
var colCValidationRange = foundValues;
var colCValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colCValidationRange).build();
activeCell.offset(0, 1).setDataValidation(colCValidationRule);
var colDValidationRange = foundValues2;
var colDValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colDValidationRange).build();
activeCell.offset(0, 2).setDataValidation(colDValidationRule);
var colEValidationRange = foundValues3;
var colEValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colEValidationRange).build();
activeCell.offset(0, 3).setDataValidation(colEValidationRule);
}
}
Take a look at these references. Understanding arrays is crucial to understanding how to loop through data.
getValues()
getValue()
This is what I wound up with. It could probably be made more streamline or efficient, but it seems to be working so far. Thank you #MiMi (and Cooper...) for all of your help! You taught me several things. Thank you!
I start by filtering all possibilities that match column A, then B,C,D and finally E is an exact match. But the following column's data validation is "re-populated" with each selection.
Please feel free to critique what I've done as I'm still learning and very likely have some redundancy going on.
function projectTasksAdjDV(e) {
var activess = SpreadsheetApp.getActive().getSheetByName('projectTasksAdj');
var datass = SpreadsheetApp.getActive().getSheetByName('projectTasks');
var colAValues = [];
var foundBValues = [];
var foundCValues = [];
var foundDValues = [];
var foundEValues = [];
var activeCell = activess.getActiveCell();
var data = datass.getRange(3,1,datass.getLastRow(),7).getValues();
const valueToFind = activeCell.getValue();
const colAVal = data;
for(var i=0;i<data.length;i++) {
if(colAVal==data[i][1]) {
colAValues.push(data[i][0]);
}
}
// Couldn't seem to get indexOf to work properly
// so this is my "workaround".
var colIndex = activess.getActiveCell().getColumn();
// Populate column B data validations
if(activeCell.getColumn() == 1 && activeCell.getRow() > 2){
activeCell.offset(0, 1).clearDataValidations();
activeCell.offset(0, 2).clearDataValidations();
activeCell.offset(0, 3).clearDataValidations();
activeCell.offset(0, 4).clearDataValidations();
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][0]) {
foundBValues.push(data[i][1]);
}
}
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][0]) {
foundCValues.push(data[i][2]);
}
}
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][0]) {
foundDValues.push(data[i][3]);
}
}
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][0]) {
foundEValues.push(data[i][6]);
}
}
if(colIndex != 0){
var colBValidationRange = foundBValues;
var colBValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colBValidationRange).build();
activeCell.offset(0, 1).setDataValidation(colBValidationRule);
var colCValidationRange = foundCValues;
var colCValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colCValidationRange).build();
activeCell.offset(0, 2).setDataValidation(colCValidationRule);
var colDValidationRange = foundDValues;
var colDValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colDValidationRange).build();
activeCell.offset(0, 3).setDataValidation(colDValidationRule);
var colEValidationRange = foundEValues;
var colEValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colEValidationRange).build();
activeCell.offset(0, 4).setDataValidation(colEValidationRule);
}
}
// Populate column C data validations
if(activeCell.getColumn() == 2 && activeCell.getRow() > 2){
activeCell.offset(0, 1).clearDataValidations();
activeCell.offset(0, 2).clearDataValidations();
activeCell.offset(0, 3).clearDataValidations();
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][1]) {
foundCValues.push(data[i][2]);
}
}
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][1]) {
foundDValues.push(data[i][3]);
}
}
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][1]) {
foundEValues.push(data[i][6]);
}
}
if(colIndex != 0){
var colCValidationRange = foundCValues;
var colCValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colCValidationRange).build();
activeCell.offset(0, 1).setDataValidation(colCValidationRule);
var colDValidationRange = foundDValues;
var colDValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colDValidationRange).build();
activeCell.offset(0, 2).setDataValidation(colDValidationRule);
var colEValidationRange = foundEValues;
var colEValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colEValidationRange).build();
activeCell.offset(0, 3).setDataValidation(colEValidationRule);
}
}
// Populate column D data validations
if(activeCell.getColumn() == 3 && activeCell.getRow() > 2){
activeCell.offset(0, 1).clearDataValidations();
activeCell.offset(0, 2).clearDataValidations();
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][2]) {
foundDValues.push(data[i][3]);
}
}
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][2]) {
foundEValues.push(data[i][6]);
}
}
if(colIndex != 0){
var colDValidationRange = foundDValues;
var colDValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colDValidationRange).build();
activeCell.offset(0, 1).setDataValidation(colDValidationRule);
var colEValidationRange = foundEValues;
var colEValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colEValidationRange).build();
activeCell.offset(0, 2).setDataValidation(colEValidationRule);
}
}
// Populate column E data validations
if(activeCell.getColumn() == 4 && activeCell.getRow() > 2){
activeCell.offset(0, 1).clearDataValidations();
for(var i=0;i<data.length;i++) {
if(valueToFind==data[i][3] && data[0][0]==data[i][0]) {
foundEValues.push(data[i][6]);
}
}
if(colIndex != 0){
var colEValidationRange = foundEValues;
var colEValidationRule = SpreadsheetApp.newDataValidation().requireValueInList(colEValidationRange).build();
activeCell.offset(0, 1).setDataValidation(colEValidationRule);
}
}
}