Reputation:
I have a spreadsheet where there is a value in column B and in column A is inserted a date, and i want to create a script that when the spreadsheet is open, inside the function onOpen (){}, checks if there is a cell in column B filled but left with column A (date) blank, then automatically inserts todays date, this needs to be done via app script, can anyone give some light?
Upvotes: 0
Views: 152
Reputation: 64042
function onOpen() {
ifBAndNotA();
}
function ifBAndNotA() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");//change sheet name as required
const sr = 2;//data startrow;
const vs = sh.getRange(sr, 1, sh.getLastRow() - sr + 1, 2).getValues();
vs.forEach((r, i) => {
if (!r[0] && r[1]) {
sh.getRange(i + sr, 1).setValue(new Date()).setNumberFormat("dd/MM/yyyy");
}
});
}
Upvotes: 1