My code is running but it doesn’t open the links from column B. The script is being executed but I don’t know why it doesn’t open the link.
It should work this way: when I click in a cell from A column it should open the cell in B column and same row.
function onSelectionChange(e) {
var sheet = e.source.getActiveSheet();
var range = e.range;
var column = range.getColumn();
var numRows = range.getNumRows();
var numCols = range.getNumColumns();
var urls = [];
if (column === 1 && numCols === 1) {
for (var i = 1; i <= numRows; i++) {
var row = range.getRow() + i - 1;
var url = sheet.getRange(row, column + 1).getValue();
urls.push(url);
}
var html = "<script>";
for (var i = 0; i < urls.length; i++) {
html += "window.open('" + urls[i] + "', '_blank');";
}
html += "</script>";
}
}
I tried to use a onEdit trigger, but my goal is to open the link in B column when I select the A column cell equivalent row. I don’t want to edit A cell to trigger this script.