Script works really well but I have 12 columns and this script only works on A and B.
function onEditTwoWay(e) {
var ss = SpreadsheetApp;
var sheet = ss.getActiveSpreadsheet();
var sheet1 = sheet.getSheetByName("Dep1");
var sheet2 = sheet.getSheetByName("Dep2");
var cell = sheet.getActiveCell();
var value = cell.getValue();
var currentRow = cell.getRow();
var currentColumn = cell.getColumn();
var activeWorksheet = ["Dep1","Dep2"];
var columnEdit = [1,2,12];
if(activeWorksheet.indexOf(ss.getActiveSheet().getName()) > -1 &&
columnEdit.indexOf(currentColumn) > -1 && currentRow > 1) {
sheet1.getRange(currentRow, currentColumn).setValue(value);
sheet2.getRange(currentRow, currentColumn).setValue(value);
};
};
Try this:
function onEdit(e) {
const sh = e.range.getSheet();
var shts = ["Dep1", "Dep2"];
var cols = [1, 2, 12];
if (~shts.indexOf(sh.getName()) && ~cols.indexOf(e.range.columnStart) && e.range.rowStart > 1) {
shts.forEach(name => {
e.source.getSheetByName(name).getRange(e.range.rowStart, e.range.columnStart).setValue(e.value);
});
}
}
All columns need to be entered in columnEdit so changed from
columnEdit = [1,2,12] to columnEdit = [1,2,3,4,5,6,7,8,9,10,11,12]
Related
I have 1 spreadsheet with multiple sheets.
The 1st and the 2nd sheets sometimes have similar data in the rows (duplicates). Also, each sheet has a column (8) with a checkbox.
Task: I need to move one of the duplicates to the 3rd sheet when the checkboxes in both sheets (1st and 2nd) are checked.
Here is the code that moves the row when it's checked in a single sheet.
Can someone help me modify it to complete my task?
function onEdit(e) {
let range = e.range;
let col = range.getColumn();
let row = range.getRow();
let val = range.getValue();
let source = e.source.getActiveSheet();
let ss = SpreadsheetApp.getActiveSpreadsheet();
let sourceSheet = ss.getSheetByName(source.getName());
if (sourceSheet.getName() == 'SHEET1' && col == 8 && val == true){
let data = sourceSheet.getRange(row,1,1,7).getValues();
let targetSheet = ss.getSheetByName('SHEET2');
targetSheet.appendRow(data[0]);
sourceSheet.deleteRow(row);
}
if (sourceSheet.getName() == 'SHEET2' && col == 8 && val == true){
let data = sourceSheet.getRange(row,1,1,7).getValues();
let targetSheet = ss.getSheetByName('SHEET3');
targetSheet.appendRow(data[0]);
sourceSheet.deleteRow(row);
}
}
Sample Spreadsheet
Apply filter()
You can add the filter() method (combined with the JSON.stringify() method) to your script to determine if a row is a duplicate of another from the other sheet. The modified script should somehow look like this:
function onEdit(e) {
var range = e.range;
var col = range.getColumn();
var row = range.getRow();
var val = range.getValue();
var source = e.source.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = ss.getSheetByName(source.getName());
var targetSheet = ss.getSheetByName('Sheet3');
//If Sheet1 checkbox is triggered
if (sourceSheet.getName() == 'Sheet1' && col == 8 && val == true) {
var rowArr = ss.getSheetByName('Sheet1').getRange(row, 1, 1, 8).getValues();
var lastRow2 = ss.getSheetByName('Sheet2').getLastRow();
var sheet2Values = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2').getRange(1, 1, lastRow2, 8).getValues();
var count = sheet2Values.filter(x => {
return (JSON.stringify(x) === JSON.stringify(rowArr[0]))
});
var otherRow = sheet2Values.map((x, i) => {
if (JSON.stringify(x) === JSON.stringify(rowArr[0])) {
return i;
}
});
if (count.length > 0) {
var otherRow = sheet2Values.map((x, i) => {
if (JSON.stringify(x) === JSON.stringify(rowArr[0])) {
return i;
}
}).filter(y => y);
rowArr[0].pop();
targetSheet.appendRow(rowArr[0]);
sourceSheet.deleteRow(row);
var otherSheet = ss.getSheetByName('Sheet2');
otherSheet.deleteRow(otherRow[0] + 1)
}
}
//If Sheet2 checkbox is triggered
if (sourceSheet.getName() == 'Sheet2' && col == 8 && val == true) {
var rowArr = ss.getSheetByName('Sheet2').getRange(row, 1, 1, 8).getValues();
var lastRow = ss.getSheetByName('Sheet1').getLastRow();
var sheet1Values = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1').getRange(1, 1, lastRow, 8).getValues();
var count = sheet1Values.filter(x => {
return (JSON.stringify(x) === JSON.stringify(rowArr[0]))
});
if (count.length > 0) {
var otherRow = sheet1Values.map((x, i) => {
if (JSON.stringify(x) === JSON.stringify(rowArr[0])) {
return i;
}
}).filter(y => y);
rowArr[0].pop();
targetSheet.appendRow(rowArr[0]);
sourceSheet.deleteRow(row);
var otherSheet = ss.getSheetByName('Sheet1');
otherSheet.deleteRow(otherRow[0] + 1)
}
}
}
Output
Based on your sample spreadsheet, the modified script should work as shown below:
Please take note that the appendRow() method appends any row to the last non-empty row in the sheet. A row with a checkbox is not considered to be an empty row thus explains the behavior of the output.
Reference
filter()
JSON.stringify()
Would that do what you want ?
function copyDuplicateRows() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet1 = spreadsheet.getSheetByName("Sheet1");
var sheet2 = spreadsheet.getSheetByName("Sheet2");
var sheet3 = spreadsheet.getSheetByName("Sheet3"); // destination sheet
var data1 = sheet1.getDataRange().getValues();
var data2 = sheet2.getDataRange().getValues();
// Use a JavaScript object to keep track of duplicate rows
var seen = {};
// Iterate through data1 and copy unique rows to sheet3
for (var i = 0; i < data1.length; i++) {
var row = data1[i];
var key = row.join(); // create a unique key for each row
if (!seen[key]) {
seen[key] = true;
sheet3.appendRow(row);
}
}
// Iterate through data2 and copy unique rows to sheet3
for (var i = 0; i < data2.length; i++) {
var row = data2[i];
var key = row.join();
if (!seen[key]) {
seen[key] = true;
sheet3.appendRow(row);
}
}
}
Trying to set a cell's data validation to be between two numbers namely, 1 and the balance of items in a budget. It keeps giving the following error:
Oct 12, 2022, 9:41:14 PM Error Exception: The parameters
(number,String) don't match the method signature for
SpreadsheetApp.DataValidationBuilder.requireNumberBetween.
at applyQtyValidation(Code:242:8)
at getQtyValidationData(Code:233:3)
at onEdit(Code:59:7)
Please help...
//Global variables
var reqSheetName = "Material Requisition";
var colStructure = 1;
var colComponent = 2;
var colWorks = 3;
var colItem = 4;
var colQty = 5;
var colUnit = 6;
var colBalance = 7;
var colBudgetCode = 8;
var colDuplicate = 18;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var wsBudget = ss.getSheetByName("Budget");
var wsRequisition = ss.getSheetByName(reqSheetName);
var rawData = wsBudget.getRange(5, 1, wsBudget.getLastRow(), 7).getValues();
var arrDetails = [];
function onEdit(e) {
//variables needed
var editedCell = e.range;
var sheetName = editedCell.getSheet().getName();
var r = editedCell.getRow();
var c = editedCell.getColumn();
var valFilter = editedCell.getValue();
//Set order qty
if (sheetName === reqSheetName && c === colItem && r > 11) {
getQtyValidationData(r);
}
}
function getQtyValidationData(r) {
var minQty = 1;
var maxQty = wsRequisition.getRange(r, colBalance).getValue();
var cell = wsRequisition.getRange(r, colQty).getA1Notation();
applyQtyValidation(minQty, maxQty, cell);
}
function applyQtyValidation(minQty, maxQty, cell) {
var rule = SpreadsheetApp
.newDataValidation()
.requireNumberBetween(minQty, maxQty)
.setAllowInvalid(false)
.setHelpText("Select a number between " + minQty + " and " + maxQty)
.build();
wsRequisition.getRange(cell).setDataValidation(rule);
}
This is working:
function onEdit(e) {
e.source.toast('Entry');
const sh = e.range.getSheet();
if (sh.getName() == "Sheet1" && e.range.columnStart == 4 && e.range.rowStart > 11) {
e.source.toast('Gate1');
sh.getRange(e.range.rowStart, 5).clearDataValidations();
var maxQty = sh.getRange(e.range.rowStart, 7).getValue();
var rule = SpreadsheetApp.newDataValidation().requireNumberBetween(1, maxQty).setHelpText(`Select a number between 1 and ${maxQty}`).setAllowInvalid(true).build();
sh.getRange(e.range.rowStart, 5).setDataValidation(rule);
}
}
I would have preferred to do it like this:
function onEdit(e) {
e.source.toast('Entry');
const sh = e.range.getSheet();
if (sh.getName() == "Sheet1" && e.range.columnStart == 4 && e.range.rowStart > 11) {
e.source.toast('Gate1');
sh.getRange(e.range.rowStart, 5).clearDataValidations();
var maxQty = sh.getRange(e.range.rowStart, 7).getValue();
let list = [...Array.from(new Array(maxQty).keys(),x => String(Number(x+1)))];
Logger.log(JSON.stringify(list));
var rule = SpreadsheetApp.newDataValidation().requireValueInList(list).setHelpText(`Select a number between 1 and ${maxQty}`).setAllowInvalid(false).build();
sh.getRange(e.range.rowStart, 5).setDataValidation(rule);
}
}
Demo:
I have 2 sheets: SheetA and SheetB with identical values in corresponding cells. I'm trying to change the cell color in SheetA when the value of the cell in SheetB changes. For example if cell A5 has value 10 in both sheets and I then change it to 5 in SheetB, I want the background color of the cell in SheetA to change
This is the code so far
function onEdit(e){
var sheetsToWatch = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SheetA");
var sheetsToEdit = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SheetB");
var cell = sheetsToEdit.getActiveCell(); // checking the active cell
var bg = '#faec15'
for (let i = 0; i < active_sheet.length; i++) {
if (sheetsToWatch.match(sheetsToEdit[i])) {
sheetsToWatch.getRange(cell.getRow(), cell.getColumn()).setBackground(bg);
} else {
return;
}
}
}
It can be done this way:
function onEdit(e){
var sheetB = e.source.getActiveSheet();
var sheetB_name = sheetB.getName();
if (sheetB_name != 'SheetB') return;
var sheetB_cell_value = e.value;
var sheetB_cell_row = e.range.rowStart;
var sheetB_cell_col = e.range.columnStart;
var sheetA = e.source.getSheetByName('SheetA');
var sheetA_cell = sheetA.getRange(sheetB_cell_row,sheetB_cell_col);
var sheetA_cell_value = sheetA_cell.getValue();
if (sheetB_cell_value != sheetA_cell_value) sheetA_cell.setBackground('#faec15');
}
function onEdit(e){
const sh = e.range.getSheet();
if(sh.getName() == 'SheetB' ) {
e.source.getSheetByName('SheetA').getRange(e.range.rowStart,e.range.columnStart).setBackground("#faec15");
}
}
The code works now. Please find my solution below
function onEdit() {
var sheetsToWatch = ['SheetA'];
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var cell = sheet.getActiveCell();
var row = cell.getRowIndex();
var column= cell.getColumnIndex();
var sheetName = sheet.getName();
var matchFound = false;
for (var i = 0; i < sheetsToWatch.length; i++) {
if (sheetName.match(sheetsToWatch[i])) matchFound = true;
}
if (!matchFound) return;
var sheetToEdit = ss.getSheetByName('SheetB');
var editRow = sheetToEdit.getLastRow();
var editColumn = sheetToEdit.getLastColumn();
for (var j = 1; j <= editRow; j++) {
for (var k = 1; k <= editColumn; k++){
var formula = sheetToEdit.getRange(j,k).getFormula();
var rowi= parseInt(formula.replace(/[^0-9]/g,''),10);
if (rowi == row){
if (k == column){
sheetToEdit.getRange(j,k).setBackground('#faec15');
}
};
}
}
}
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.
I have the following Google Apps onEdit Script which looks up the table in columns A:D in my 'DropDown Lists' sheet. This works for the dropdown in column C of the 'HISOP Training' sheet when the Branch is selected in the dropdown in column A of the same sheet:
//Dynamic Dropdown for HISOP Training
{
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var tablists = 'Dropdown Lists';
var tabValidation = 'HISOP Training';
var ss = spreadsheet.getActiveSheet();
var datass = spreadsheet.getSheetByName(tablists);
var activeCell = ss.getActiveCell();
if (
activeCell.getColumn() == 1 &&
activeCell.getRow() > 1 &&
ss.getSheetName() == tabValidation
) {
activeCell
.offset(0, 2)
.clearContent()
.clearDataValidations();
var base = datass.getRange(2, 1, 1, 5).getValues();
var baseIndex = base[0].indexOf(activeCell.getValue()) + 1;
Logger.log(baseIndex);
if (baseIndex != 0) {
//Dynamic dropdown for 'Employee'
var validationRange = datass.getRange(6, baseIndex, 150);
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 2).setDataValidation(validationRule);
}
}
if (ss.getSheetName() == tabValidation) {
var lock = LockService.getScriptLock();
if (lock.tryLock(0)) {
autoid_(ss);
lock.releaseLock();
}
}
}
I now also want the dropdown in column D of the 'HISOP Training' sheet to select from the range BO:BR of the 'Dropdown List' sheet when the Branch in Column A of the 'HISOP Training' sheet is selected but I don't know how to write the script for this.
This is an image of my 'HISOP Training' sheet:
This is a link to a sanitised version of my spreadsheet:
Spreadsheet
I would really appreciate some help with this.
Final answer:
function myOnEdit(e){
var sheet = SpreadsheetApp.getActive().getSheetByName('HISOP Training');
var sheet2 = SpreadsheetApp.getActive().getSheetByName('Dropdown Lists');
var value = e.value;
var col = e.range.getColumn();
var row = e.range.getRow();
if(col==1 && e.range.getValue()=='New York' && row>2 && e.range.getSheet().getName()=='HISOP Training'){
// 2 is for dropdown D
var dropdownData = sheet2.getRange("A6:A150").getValues().flat();
var dropdownData2 = sheet2.getRange("BO4:BO150").getValues().flat();
var allowDropdown = sheet.getRange(row, col+2).clearDataValidations().clearContent();
var allowDropdown2 = sheet.getRange(row, col+3).clearDataValidations().clearContent();
var rule = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData, true).build();
var rule2 = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData2, true).build();
allowDropdown.setDataValidation(rule);
allowDropdown2.setDataValidation(rule2);
}
if(col==1 && e.range.getValue()=='London' && row>2 && e.range.getSheet().getName()=='HISOP Training'){
var dropdownData = sheet2.getRange("B6:B150").getValues().flat();
var dropdownData2 = sheet2.getRange("BP4:BP150").getValues().flat();
var allowDropdown = sheet.getRange(row, col+2).clearDataValidations().clearContent();
var allowDropdown2 = sheet.getRange(row, col+3).clearDataValidations().clearContent();
var rule = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData, true).build();
var rule2 = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData2, true).build();
allowDropdown.setDataValidation(rule);
allowDropdown2.setDataValidation(rule2);
}
if(col==1 && e.range.getValue()=='Paris' && row>2 && e.range.getSheet().getName()=='HISOP Training'){
var dropdownData = sheet2.getRange("C6:C150").getValues().flat();
var dropdownData2 = sheet2.getRange("BQ4:BQ150").getValues().flat();
var allowDropdown = sheet.getRange(row, col+2).clearDataValidations().clearContent();
var allowDropdown2 = sheet.getRange(row, col+3).clearDataValidations().clearContent();
var rule = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData, true).build();
var rule2 = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData2, true).build();
allowDropdown.setDataValidation(rule);
allowDropdown2.setDataValidation(rule2);
}
if(col==1 && e.range.getValue()=='Tokyo' && row>2 && e.range.getSheet().getName()=='HISOP Training'){
var dropdownData = sheet2.getRange("D6:D150").getValues().flat();
var dropdownData2 = sheet2.getRange("BR4:BR150").getValues().flat();
var allowDropdown = sheet.getRange(row, col+2).clearDataValidations().clearContent();
var allowDropdown2 = sheet.getRange(row, col+3).clearDataValidations().clearContent();
var rule = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData, true).build();
var rule2 = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData2, true).build();
allowDropdown.setDataValidation(rule);
allowDropdown2.setDataValidation(rule2);
}
}
Solution
From my interpretation of your question you want to be able to only select a dropdrown of values in columns C and D only if a specific value is selected in column A. To provide a solution to this question instead of providing a specific answer to your sheet case I have provided a general solution abstracting the question so that others with similar questions can easily interpolate the answer and use it as well. You will just need to adapt this answer to you case.
To achieve this I have set up a conditional on an onEdit function to catch changes in the sheet and if this conditional is met (in your case if the branch in column A is selected) then you will be able to select from C and D dropdowns. The following code that solves the issue has self explanatory comments:
function onEdit(e) {
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
// Get the value of the cell changed
var value = e.value;
// Get col and row of the cell changed to make sure it was in col A
var col = e.range.getColumn();
var row = e.range.getRow();
// If col A. Here you could also add another condition to the if for instance if the value on col A
// is equal to whatever value you want to select in the dropdown in A, then execute this
if(col==1 && e.range.getValue()=='VALUE 1'){
// Get the data for the range of the dropdown. Here you choose if you want to insert dropdowns for C and D
var dropdownData = sheet.getRange("C1:C5").getValues().flat();
// Get the cell we will let the dropdown go (clear all previous content and data validations)
// In your case these you be the columns D and
var allowDropdown = sheet.getRange(row, col+1).clearDataValidations().clearContent();
// Create rules for the respective dropdowns of C and D (in this case is just one rule because I am
// just using a single dropdown to exemplify how to do this
var rule = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData, true).build();
// Set the data validation
allowDropdown.setDataValidation(rule);
}
// SECOND RANGE. REPEAT FOR THE REST IF WE HAVE MORE SUB RANGES
if(col==1 && e.range.getValue()=='VALUE 2'){
var dropdownData = sheet.getRange("D1:D5").getValues().flat();
var allowDropdown = sheet.getRange(row, col+1).clearDataValidations().clearContent();
var rule = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData, true).build();
allowDropdown.setDataValidation(rule);
}
}
And this is how this example would look like in the sheet:
As you seem to have difficulties understanding, I have adjusted the general case scenario to your specific situation and I have done for you both the right dropdowns for columns C and D. These are as follow:
function onEdit(e) {
var sheet = SpreadsheetApp.getActive().getSheetByName('HISOP Training');
var sheet2 = SpreadsheetApp.getActive().getSheetByName('Dropdown Lists');
var value = e.value;
var col = e.range.getColumn();
var row = e.range.getRow();
if(col==1 && e.range.getValue()=='New York' && row>2 && e.range.getSheet().getName()=='HISOP Training'){
// 2 is for dropdown C
var dropdownData = sheet2.getRange("BO4:BO49").getValues().flat();
var dropdownData2 = sheet2.getRange("Z2:Z4").getValues().flat();
var allowDropdown = sheet.getRange(row, col+3).clearDataValidations().clearContent();
var allowDropdown2 = sheet.getRange(row, col+2).clearDataValidations().clearContent();
var rule = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData, true).build();
var rule2 = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData2, true).build();
allowDropdown.setDataValidation(rule);
allowDropdown2.setDataValidation(rule);
}
if(col==1 && e.range.getValue()=='London' && row>2 && e.range.getSheet().getName()=='HISOP Training'){
var dropdownData = sheet.getRange("BP4:BP45").getValues().flat();
var dropdownData2 = sheet2.getRange("AA2:AA3").getValues().flat();
var allowDropdown = sheet.getRange(row, col+1).clearDataValidations().clearContent();
var allowDropdown2 = sheet.getRange(row, col+2).clearDataValidations().clearContent();
var rule = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData, true).build();
var rule2 = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData2, true).build();
allowDropdown.setDataValidation(rule);
allowDropdown2.setDataValidation(rule);
}
if(col==1 && e.range.getValue()=='Paris' && row>2 && e.range.getSheet().getName()=='HISOP Training'){
var dropdownData = sheet.getRange("BQ4:BQ43").getValues().flat();
var dropdownData2 = sheet2.getRange("AB2:AB4").getValues().flat();
var allowDropdown = sheet.getRange(row, col+1).clearDataValidations().clearContent();
var allowDropdown2 = sheet.getRange(row, col+2).clearDataValidations().clearContent();
var rule = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData, true).build();
var rule2 = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData2, true).build();
allowDropdown.setDataValidation(rule);
allowDropdown2.setDataValidation(rule);
}
if(col==1 && e.range.getValue()=='Tokyo' && row>2 && e.range.getSheet().getName()=='HISOP Training'){
var dropdownData = sheet.getRange("BR4:BR33").getValues().flat();
var dropdownData2 = sheet2.getRange("AC2:AC3").getValues().flat();
var allowDropdown = sheet.getRange(row, col+1).clearDataValidations().clearContent();
var allowDropdown2 = sheet.getRange(row, col+2).clearDataValidations().clearContent();
var rule = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData, true).build();
var rule2 = SpreadsheetApp.newDataValidation().requireValueInList(dropdownData2, true).build();
allowDropdown.setDataValidation(rule);
allowDropdown2.setDataValidation(rule);
}
}
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)