I wrote a custom in-cell function for having a specified data validation list only if a given cell isn't empty. Here's that function:
function CONDITIONALVALIDATION(sheetName,cellToCheckA1,validationCell,validationItems){
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName(sheetName);
var cellValue = sheet.getRange(cellToCheckA1).getValue();
var cellToSet = sheet.getRange(validationCell);
cellToSet.clearDataValidations();
if(cellValue!=""){
var unitsRule = SpreadsheetApp.newDataValidation().requireValueInList(validationItems, true);
cellToSet.setDataValidation(unitsRule)
}
}
When I call a test function which fills the parameters for the CONDITIONALVALIDATION function and run it within the editor, I see the desired results. That function is the following:
function testconditional(){
CONDITIONALVALIDATION("Front End","E12","F12",["x","y"]);
}
However, when I call the function as a custom in-cell function, I constantly get a
"Formula Parse Error."
I have already ruled out syntax as a possible cause; the call to the function in my test function is the exact same as when I call it within a custom in-cell function. Save, of course, the equals sign before the function call to indicate that it is a function to be run. I also know that the function is recognized by sheets; there is no "Function nonexistant", or "#NAME?" error when the function is called within the cell.
How do I solve this problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…