Situation: Data validation on cells that refer to a range via direct reference (A1Notation) and Data Validation on other cells that refer to a named range.
Works both.
When duplicating the sheet, both still work. However, when resetting the data validations manually to the same ranges or via my script, the data validation of the cell where the data validation refers via named range will not work and there is no way to set it up again by referring via named range either manually or by copying (.getDataValidation / .setDataValidation) via script.
Check out the example - run script function cp_dataValidation() either on Sheet1 and Copy of Sheet1 as an active sheet. Then click the data validation dropdowns in the cells.
Eventually, my goal is to perform a copy of the data validation (referring to a named range) from one range to another on a duplicated sheet via script.
function cp_dataValidation() {
var sheet = SpreadsheetApp.getActiveSheet()
//cell with data validation referring to a named range
var named_range_tmpl = sheet.getRange("B2");
//cell with data validation referring to a range via A1Notation
var range_tmpl = sheet.getRange("C2");
//target cells to copy dataValidation to
var nr_target = sheet.getRange("D2");
var r_target = sheet.getRange("E2");
nr_target.setDataValidation(named_range_tmpl.getDataValidation());
r_target.setDataValidation(range_tmpl.getDataValidation());
Logger.log(JSON.stringify(named_range_tmpl.getDataValidation(), null, 2));
Logger.log(JSON.stringify(range_tmpl.getDataValidation(), null, 2));
}
the data validation of the cell where the data validation refers via named range will not work
, when I used your sample Spreadsheet and your script (runcp_dataValidation()
), unfortunately, I couldn't replicate your situation. Can I ask you about the method for replicating your issue? By the way, can you add your script in your question? – Tanaike