Created
July 26, 2019 02:05
-
-
Save henriquebastos/2ab002071f35a41afb38b9ec9a0b5065 to your computer and use it in GitHub Desktop.
Dynamic Validator by Reference for Google Spreadsheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onEdit(e) { | |
var rule = e.range.getDataValidation(); | |
if (rule != null) { | |
var value = e.range.getCell(1,1).getValue(); | |
var criteria = rule.getCriteriaType(); | |
var validationRange = rule.getCriteriaValues()[0]; | |
var i = findInRange(value, validationRange.getValues()); | |
var ref = validationRange.getCell(1,1).offset(i, 0).getA1Notation(); | |
e.range.getCell(1,1).setFormula("=" + ref); | |
} | |
} | |
function findInRange(value, tableValues){ | |
for (var i = 0; i < tableValues.length; i++) { | |
if(tableValues[i][0] == value) { | |
return i; | |
} | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment