# Get Last Modified Date When Cell is changed

**URL:** <https://community.glideapps.com/t/get-last-modified-date-when-cell-is-changed/12359>\
**Category:** Ask for Help\
**Created:** [July 12, 2020, 4:51pm UTC](https://community.glideapps.com/t/get-last-modified-date-when-cell-is-changed/12359 "2020-07-12T16:51:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrurka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mrurka/32/7381_2.png) [@mrurka](https://community.glideapps.com/u/mrurka)\
**Post date:** [July 12, 2020, 4:51pm UTC](https://community.glideapps.com/t/get-last-modified-date-when-cell-is-changed/12359/1 "2020-07-12T16:51:30Z")

</div>

Hey, could some help having “Last Modified” date appear and update when a particular cell is modified.

I have a very simple Scripts formula in Sheets (see below). It works fine when I manually edit the sheet, but doesn’t work when Glide updates the sheet.

I also tried `onChange` and `onFormSubmission` — none of these work ☹

————

function onEdit(e) {

var row = e.range.getRow();  
var col = e.range.getColumn();

if (col === 1 && row \> 1 && e.source.getActiveSheet().getName() === “Tasks” ) {  
e.source.getActiveSheet().getRange(row, 8).setValue(new Date())  
}  
}

———

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [July 12, 2020, 10:27pm UTC](https://community.glideapps.com/t/get-last-modified-date-when-cell-is-changed/12359/2 "2020-07-12T22:27:19Z")

</div>

The onChange and onEdit is only the name of the function. Go to Edit \> Current project’s triggers and add a trigger for your function with the event type On change.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [July 13, 2020, 2:58am UTC](https://community.glideapps.com/t/get-last-modified-date-when-cell-is-changed/12359/3 "2020-07-13T02:58:38Z")

</div>

Oh I just realized if you enable the edit option for the item, you can capture the current datetime value into a field of your choice, so that’s the better option for you I suppose.

---

<div class="post-metadata">

**Author:** ![mthakershi](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mthakershi/32/1715_2.png) [@mthakershi](https://community.glideapps.com/u/mthakershi)\
**Post date:** [July 13, 2020, 3:49am UTC](https://community.glideapps.com/t/get-last-modified-date-when-cell-is-changed/12359/4 "2020-07-13T03:49:57Z")

</div>

This is how I do it.

I have a function in my script associated with “On change” event. I handle EDIT, INSERT\_ROW with it.

```
function changeTriggerProcessing(e) {
  // Logger.log(e.changeType);

  let sheetName = e.source.getActiveSheet().getName();

  // in case of EDIT, the way to get active sheet is different
  if (e.changeType == "EDIT") {
    sheetName = SpreadsheetApp.getActiveSheet().getName();
  }

  if (
    e.changeType == "EDIT" &&
    sheetName == "SHEET_1" &&
    SpreadsheetApp.getActiveSheet().getActiveCell().getHeight() == 1 &&
    SpreadsheetApp.getActiveSheet().getActiveCell().getWidth() == 1
  ) {
    let ss = SpreadsheetApp.getActiveSpreadsheet();
    let sh = ss.getSheetByName("Audit Log");
    let rowIndex = SpreadsheetApp.getActiveSheet()
      .getActiveCell()
      .getA1Notation()
      .replace(/\D/g, "")
      .trim();

    // detect delete from the App (anchor cells become blank)
    if (
      !SpreadsheetApp.getActiveSheet()
        .getRange("A" + rowIndex)
        .getValue() &&
      !SpreadsheetApp.getActiveSheet()
        .getRange("D" + rowIndex)
        .getValue()
    ) {
      // whole row deleted case
      // your code here
    } else {
      // update case
      // your code here
    }
  } else if (sheetName == "App: Logins" && e.changeType == "INSERT_ROW") {
    let ss = SpreadsheetApp.getActiveSpreadsheet();
    let sh = ss.getSheetByName("Audit Log");
    let rowIndex = SpreadsheetApp.getActiveSheet().getLastRow();

    // INSERT_ROW processing here
    // your code here
  }
}
```

---

<div class="post-metadata">

**Author:** ![Pat\_Baker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pat_baker/32/2472_2.png) [@Pat\_Baker](https://community.glideapps.com/u/Pat_Baker)\
**Post date:** [September 2, 2020, 9:40am UTC](https://community.glideapps.com/t/get-last-modified-date-when-cell-is-changed/12359/5 "2020-09-02T09:40:03Z")

</div>

Hi,

Would it be more understandable to replace :

> [@mthakershi](#):
>
> ```auto
> let rowIndex = SpreadsheetApp.getActiveSheet()
> .getActiveCell()
> .getA1Notation()
> .replace(/\D/g, "")
> .trim();
> 
> ```

with :

```auto
    let rowIndex = SpreadsheetApp.getActiveSheet()
      .getActiveCell()
      .getRowIndex();

```
