I'm trying to create a custom onEdit function with google sheets script editor. I want to know if its possible to add an input parameter such as onEdit(e,row) where row is an integer I use to specify a target cell. Here is my noob code:
function onEdit(e,row) {
// writes the current date to the cell in column B on the same row when a cell in a specific column is edited
var sheetNameToWatch = "M2";
var columnNumberToWatch = /* column */ 7; // column A = 1, B = 2, etc.
var ss = SpreadsheetApp.getActiveSpreadsheet(); // not used atm
var sheet = SpreadsheetApp.getActiveSheet(); // sheet on which changes are tracked
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("GRID-TRACKING") // sheet that contains formula cells
var range = sheet.getActiveCell(); // active cell is cell being edited
if (sheet.getName() == sheetNameToWatch && range.getColumn() == columnNumberToWatch) {
var targetCell = sheet2.getRange(row, 2); // I want the input parameter to control the "row" so I can autofill
targetCell.setValue("" + Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd")); // writes current date to cell
}
}
I'm using this to write the latest date of any edit on sheet "M2" column G to the sheet with formulas("GRID-TRACKING"). I put the formulas in column A and write the dates to column B. The problem is that my "row" variable is undefined...if I replace it with a fixed number and dont try to add the parameter at all it works fine, but I need a parameter I can autofill.
in the cell my formula is =onedit(cell,row)
Thanks,
Umpsy