r/GoogleAppsScript • u/CartographerAsleep66 • Mar 03 '26
Question Help for School Project
We are simulating a production environment and need to track progress. We have a label maker and labels, but we need a way to track when something was scanned. I am trying to make a script that will enter the current time in the B column when data is scanned into the A column. Currently, whenever something is edited on the whole sheet, the time changes for every cell in the B column. Also, is there a way to make sure this will work with multiple sheets in the same file, without changing the times on the other sheets?
function onEdit(e) {
// Get the edited range and sheet
var sheet = e.range.getSheet();
var editedRow = e.range.getRow();
var editedCol = e.range.getColumn();
// Change 'YourSheetName' to your actual sheet name
if (sheet.getName() !== 'Post Reflow 1') return;
if (sheet.getName() !== 'Post AOI 1') return;
if (sheet.getName() !== 'Post Reflow 2') return;
if (sheet.getName() !== 'Post AOI 2') return;
if (sheet.getName() !== 'Post X-Ray') return;
if (sheet.getName() !== 'Post FFT') return;
if (sheet.getName() !== 'Post Rework') return;
// Check if the edit was made in column B (column index 2) and not a header row
if (editedCol === 1 && editedRow > 1) {
var timestampCell = sheet.getRange(editedRow, 2); // Column C for timestamp
// Only set timestamp if the cell in column B is not empty
if (range.getColumn() === codeColumn && range.getValue() !== "") {
// Set current timestamp in the same row, timestamp column
sheet.getRange(range.getRow(), timestampColumn)
.setValue(new Date());
}
}
View all comments
Show parent comment
1
u/RussellJP Mar 17 '26
Does this mean your currently selected cell becomes the hypothetical onEdit event object? Or what is this doing under the hood? I’ve always found troubleshooting onEdit functions cumbersome but if there was a way to make things more transparent that would be a game changer. Like the ability to log certain values via Run. Instead of spreadsheet.toast-ing them at runtime on the actual sheet.