I'm trying to create a data validation using appscript. The code below is working but only for a single cell, Now I want to apply the validation for the whole column.
The validation gets applied on cell G5 when the cell C5 = Office and cell D5 = Retail and the values for the validation are sitting in different tab named "rentals".
If I try try to use C:C and D:D nothing happens.
Can someone please explain me where I went wrong?
Thanks!
function onEdit() {
var ss = SpreadsheetApp.getActive();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('final rough');
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('rentals');
var cell2 = sheet.getRange("C5").getValues(); //<< Get the values
var cell3 = sheet.getRange("D5").getValues(); //<< of these cells
var cell4 = sheet2.getRange("E2").getValue();
var cell5 = sheet2.getRange("F2").getValue();
var cell6 = sheet.getRange("G5");
var rule = SpreadsheetApp.newDataValidation()
.requireNumberBetween(cell4, cell5)
.setAllowInvalid(false)
.build();
if(cell2 == "Office" && cell3 == "Retail"){
cell6.setDataValidation(rule);
}
}