Reputation: 3
I'm just over my head with the loop, I have tried few variations I've found from here but I can't get anything to work. And now I'm just confused what part I took from where and starting from scratch again.
This is what I want, but for all year/12 sheets
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "jan22" ) {
var r = s.getActiveCell();
if( r.getColumn() == 4 ) {
var nextCell = r.offset(0, -3);
if( nextCell.getValue() === '' )
nextCell.setValue(new Date());
}
}
}
I have tried the var sheets = ["feb22", "mar22", "apr22", "may22", "jun22", "jul22", "aug22", "sep22", "oct22", "nov22", "dec22" ];
I found from here Google script: adapting script to apply to multiple sheets, quick correction
I also tried what I found from here Google Sheets Script: How to run function on loop over all sheets in workbook and onOpen? and here Copy row to another sheet via for loop google sheets script
But I started getting errors that even ss.getsheets is not correct term. I think I just cannot remove the unrelated commands/add the relevant ones. (This is 3rd day in my life I've even known about Apps Script)
Upvotes: 0
Views: 93
Reputation: 27292
If you'd want the function to all sheets in the spreadsheet, you can remove the first if-statement.
Try
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
var r = s.getActiveCell();
if( r.getColumn() == 4 ) {
var nextCell = r.offset(0, -3);
if( nextCell.getValue() === '' )
nextCell.setValue(new Date());
}
}
and see if that works?
Upvotes: 0