r/GoogleAppsScript • • Sep 19 '25

Question How to make my script faster?

Hello, would anyone be able to help me with this script, so it would run faster? I might have around 30 users writing into my sheet at the same time and I want to know the timestamp when they write new info in specific column. The code works, but it feels quite slow:

function onEdit(e) { addTimestamp(e); }

function addTimestamp(e){ var targetColumn = 6; var tab = e.source.getActiveSheet().getName(); var startRow = 6; var row = e.range.getRow(); var col = e.range.getColumn();

if(col === targetColumn && row >= startRow && tab === tab && e.source.getActiveSheet().getRange(row,11).getValue() == ""){ e.source.getActiveSheet().getRange(row,11).setValue(new Date()); }

if(col === targetColumn && row > 5 && tab === tab && e.source.getActiveSheet().getRange(row,6).getValue() == "" && e.source.getActiveSheet().getRange(row,11).getValue() != ""){ e.source.getActiveSheet().getRange(row,11).clearContent(); } }

3 Upvotes

14 comments sorted by

View all comments

Show parent comment

1

u/True_Teacher_9528 Sep 20 '25

That’s a good point, I wonder if you create a script that is bound to a hotkey that would create and delete a row, while storing the info about the row being created and deleted. I personally try to avoid onedit like the plague especially if there’s a lot of traffic on the sheet because you just end up making a ton of unnecessary calls.

1

u/mommasaidmommasaid Sep 21 '25 edited Sep 21 '25

If you "required" them to use that macro you could just dump the properties cache to the sheet before performing a row insert/delete.

Perhaps you could data protect the timestamp column so they wouldn't be able to insert/delete rows on their own.

Or you could let them insert/delete and detect that with an onChange() trigger, but it could be disastrous if the onChange() didn't execute for whatever reason.

A faster/simpler solution may be using self-referencing formulas, perhaps with some script helping. See my other top-level reply.