I’m wondering if theres anyway to shorten this code. I need to find and replace a bunch of phrases with the hyperlinked version of the phrase, and I’m hoping there is a more efficient way to do it. Thank you in advance!!
function insertUrl() {
let ranges = SpreadsheetApp.getActive()
.createTextFinder("Example 1")
.matchEntireCell(true)
.matchCase(true)
.matchFormulaText(false)
.ignoreDiacritics(true)
.findAll();
ranges.forEach(function(range){
range.setFormula('=HYPERLINK("https://www.website1.com/","Example 1")');
}
);
{
let ranges = SpreadsheetApp.getActive()
.createTextFinder("Example 1")
.matchEntireCell(true)
.matchCase(true)
.matchFormulaText(false)
.ignoreDiacritics(true)
.findAll();
ranges.forEach(function(range){
range.setFormula('=HYPERLINK("https://www.website2.com/","Example 1")');
}
);
}
{
let ranges = SpreadsheetApp.getActive()
.createTextFinder("Example 3")
.matchEntireCell(true)
.matchCase(true)
.matchFormulaText(false)
.ignoreDiacritics(true)
.findAll();
ranges.forEach(function(range){
range.setFormula('=HYPERLINK("https://www.website3.com/","Example 3")');
}
);
}
}