Reputation: 669
I know you can use .getDataValidation() or .getDataValidations() to access the rules set on a data validated cell, but is it possible to access the actual range that a validation is referencing?
For example, if SHEET is my active sheet and cell A1 is a data validated cell that has a criteria of "List from a range", and that range is Sheet2!B2:B100, can I return this range programmatically?
var rules = SHEET.getRange("A1").getDataValidations();
for (var i = 0; i < rules.length; i++) {
for (var j = 0; j < rules[i].length; j++) {
var rule = rules[i][j];
if (rule != null) {
var criteria = rule.getCriteriaType();
var args = rule.getCriteriaValues();
}
}
}
Upvotes: 1
Views: 2237
Reputation: 24609
Yes, getCriteriaValues()
will return a 2-element array, where the first element is the range object you are requiring, and the second element is a boolean value signifying whether there is a drop-down arrow in the cell.
https://developers.google.com/apps-script/reference/spreadsheet/data-validation#getCriteriaValues()
Upvotes: 2