In google sheets, I'd like my custom function to use one of the built-in functions. Specifically, this function would take a string as a parameter, comb through another sheet to locate that value, and then return a link to that cell's address.
function href(findMe) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var hrefSheet = ss.getSheetByName("otherSheet");
hrefSheet.activate();
var rows = hrefSheet.getDataRange();
var numRows = rows.getNumRows();
var finds = rows.getValues()[1][0];
var hrefCellRow;
for(var i=0; i<numRows; i++){
if(finds[i][0] == findMe){
hrefCellRow = i+1;
break;
}
}
return address(hrefCellRow, 1); //address() is a function that is built in to sheets
}
So if I have a value "XYZ" in the "otherSheet" sheet, when I type
=href("XYZ")
I'd like it to try to find the value XYZ and return an address to the active cell. Extra kudos if it returns an actual link that when clicked, goes to that cell.