I'm trying to figure out how to write scripts for Google tables, I can’t solve the following problem:

There is a column "A" on sheet 1, where changes are daily made in each cell. How to create a column "A" on sheet 2, where in each cell will be made the dates of time for making changes in the column "A" of 1 sheet? In order to be able to check the time when changes were made to a particular cell in column "A" on page 1.

I understand that the onEdit function is used here:

The function onEdit (e) {// Set a comment on the cell to be used. var range = e.range; range.setNote ('Last modified:' + new Date ()); }

The code must start with the function editTables (// document ID //)

But that's all I managed to figure out. I can not figure out how to assign ranges, cells, columns and rows in Google tables to move forward somehow.

If anyone knows how to implement this script, please help.

Here is an example of what this should look like as a result: Fig. 1 (Column "A" on sheet 1 where changes are made) Fig. 2 (Column "A" on sheet 2 where the dates of the time of making changes are entered in column "A" on sheet 1 shown in Figure 1)

    1 answer 1

    You need something like this

    function onEdit(e) { try { if (!e || !e.range) return; if (e.range.getColumn() === 1 && e.range.getSheet().getName() === 'Sheet1') e.source.getSheetByName('Sheet2').getRange(e.range.getRow(), 1, 1, 1).setValue(new Date()); } catch (err) { SpreadsheetApp.getActiveSpreadsheet().toast(err.message); } } 
    • we first check for the presence of the correct argument passed to the function
    • then it is checked whether the variable cell is column A of Sheet1
    • when fulfilling conditions, changes are made to Sheet2
    • error catching added
    • one
      Many thanks! Very helpful! - Alexander Latypov