1

See this thread: https://productforums.google.com/forum/#!category-topic/docs/how-do-i/_oFmvMZUCqg

In particular this script:

function onEdit(e){
  // Set a comment on the edited cell to indicate when it was changed.
  var range = e.range;
  range.setNote('Last modified: ' + new Date());
}

Also found here: https://developers.google.com/apps-script/guides/triggers/#onedit

I'm looking to make this happen only for cells in a certain column, and not sure how to modify the script accordingly (or if I should take a different approach).

2

You can test the Column the edited cell is in and then act on the cell if it is in the appropriate column. So for Column C:

function onEdit(e){
  // Set a comment on the edited cell to indicate when it was changed.
  var range = e.range;
  var rangeCol = range.getColumn();
  if(rangeCol === 3){
    range.setNote('Last modified: ' + new Date());
  }
}

.getColumn() returns the column number. Other options can be found at the documentation for the Range class.

2
  • Thanks Karl! So is e.range specifically asking for the range information from the event? Just trying to understand what's going on with that part.
    – Drewdavid
    Mar 9 '17 at 20:09
  • 1
    e represents data from the event. So e.range is the range of the action which triggered the event and .getColumn() returns the first column. So if a group of cells is selected the code will only run IF the first column matches. If there is a chance that multiple cells are edited at one time and you need to act on them, you may need additional code. Look that the linked Range Class documentation for more on that. And create a second question after trying a few things if needed. Be sure to include code if you do.
    – Karl_S
    Mar 9 '17 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.