2
votes

I'm very, VERY new at this. Sorry in advance for my ignorance.

I'm trying to auto-fill a column with a date across multiple sheets. I have 4 different sheets, and I'm trying to automatically have the datestamp fill in on the first column when data is entered into the second column. I'd like that exact same action to take place on all 4 sheets. I can successfully get 1 sheet to do this at a time, but not all 4.

I know it seems very finicky to be asking for a script to date things for us, but it would help out our data entry guys quite a bit.

This is what I have:

function onEdit(event) {
     var sheetName = 'Customer Received',
         watchCol = [2], 
         stampCol = [1],
         ind = watchCol.indexOf(event.range.columnStart);
     if (event.source.getActiveSheet()
         .getName() !== sheetName ||  ind == -1 || event.range.rowStart < 4) return;
    event.source.getActiveSheet()
             .getRange(event.range.rowStart, stampCol[ind])
             .setValue(event.value ? new Date() : null);
 }

This script does what it needs to on ONE sheet. I tried creating 3 more scripts exactly like the above, just with replacing "Customer Received" with the other sheet names; this resulted in only one of those sheets functioning properly. I learned from the thread below that I can't do multiple onEdit scripts for one sheet, which is why my 1st attempt wasn't working.

Google script to work across multiple sheets

I got this far with help from these two threads (plus one more than I can't find now; darn me for not bookmarking):

Auto-updating column in Google Spreadsheet showing last modify date

Google Spreadsheet Timestamp?

Basically, I've found a lot of help on this website to get me some of the answers to my questions, but I'm not all the way there yet. Can any of you push me the rest of the way? :) Is what I'm looking for even possible?

1
You are almost there. OnEdit gets called on edit event for every sheet, so the only bit that is missing is an array of sheets which you want to date-stamp or, if all sheets need to be date-stamped, then simply get the active sheet and that's it. Done.matcheek

1 Answers

0
votes

Dropping the check for sheet name will make it work for all sheets in particular worksheet

function onEdit(event) {
     var watchCol = [2], 
         stampCol = [1],
         ind = watchCol.indexOf(event.range.columnStart);

     if (ind == -1 || event.range.rowStart < 4) return;

     event.source.getActiveSheet()
       .getRange(event.range.rowStart, stampCol[ind])
       .setValue(event.value ? new Date() : null);
 }