I've got a list of hyperlinks stored in a range and I would like to have the data validation in a different column allow you to choose from the link "text" and then paste the full cell formula. The way it works at the moment the data validation cell only contains the cell value.
Link to example sheet
Some sheet function code:
C2: =HYPERLINK("#rangeid=901904080","Cell E2")
C3: =HYPERLINK("#rangeid=951806747","Cell E3")
C4: =HYPERLINK("#rangeid=743771733","Cell E4")
Auto recorded script code:
function DV() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('C2').activate();
spreadsheet.getRange('A2:A').setDataValidation(SpreadsheetApp.newDataValidation()
.setAllowInvalid(false)
.requireValueInRange(spreadsheet.getRange('Sheet2!$C$2:$C'), true)
.build());
};
Is there something I can do to the script code to make it paste the formula in stead of the value? Or is the best option to try and trigger on when a new value is chosen and then do something like:
Att! Pseudo code
onEdit(e){
//pseudo code
if e.range in column A{
var sourceRange = sheet.getRange("C2:C")
var index = sourceRange.indexOf(e.range.getValue())
e.range.setFormula(sourceRange[index].getFormula())
}
}