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/WicketTheQuerent Mar 05 '26 edited Mar 05 '26
Thanks.
So, it looks like you tried to run the onEdit function using the Run button.
To test this function, you should edit a cell using the Google Sheets web app or the mobile app.
If you insist on using the Run button, you have to assign an object to the e parameter.
One one is to create a tester function like this:
Note: The above function is just a starting point, but it should be good enough to test your onEdit function.
Then select the tester instead of onEdit in the function dropdown, then click Run.