I've created a spreadsheet then added some values. I opened the script editor through the menu and added an onEdit function. I cannot, for the life of me, get that script to do anything when I edit a cell in the sheet.
It will run if I specifically press the "run" button in the editor, but that sort of defeats the purpose. What am I missing?
in case it matters here is my code
function onBugEdit() {
Browser.msgBox("test");
var sheet = SpreadsheetApp.getActiveSheet();
var rng = sheet.getActiveRange();
var val = rng.getValues();
var col = rng.getColumn();
var row = rng.getRow();
var h_string = '=HYPERLINK("http://example.com?id='+val+'","'+val+'")';
if(col == 4) {
col = "D";
cell = sheet.getRange(col+row);
cell.setFormula(h_string);
}
};
The project trigger is set for the onEdit function but again nothing happens when I edit a cell.
Have you tried calling your function onEdit
not onBugEdit
?
Also remember that "edit" is registered when you exit the cell after editing it.
your code could be simplified to:
function onEdit(e) {
if(e.range.getColumn() == 4) {
makeHyperlink(e)
}
};
function makeHyperlink(e) {
e.range.setFormula('=HYPERLINK("http://example.com?id='+e.value+'","'+e.value+'")');
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.