简体   繁体   中英

Timestamp a cell in Google Sheets if the color of another cell is changed

I have a function that works great when someone updates a cell in Google Sheets.

   function getDate() {
      return new Date();
    }

eg =getDate(A2) will timestamp the cell it's entered in every time A2 is updated

However, it doesn't update when I highlight the cell with a color. What else do I need to implement this? Thanks

Use an installable on change trigger to capture events where changeType is EDIT or FORMAT in an onEditOrFormat(e) function that checks whether SpreadsheetApp.getActiveCell() is in the list of cells that should trigger a timestamp in another cell.

Your onEditOrFormat() function must run on a trigger rather than through a spreadsheet formula. You cannot get a permanent timestamp with a spreadsheet formula, even with a custom function, because formula results are refreshed from time to time. When that happens, the custom function gets recalculated and the original timestamp is lost.

The easiest way to insert the current date in a cell is to press Control +; or ⌘; . See the keyboard shortcuts help page.

Many people use simple onEdit(e) triggers to create static timestamps. Search this forum for many examples, or take a look at the timestampMultipleColumns_ script. Unfortunately, simple triggers cannot capture FORMAT events.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM