-1

I am trying to use the following generic script, and only apply it to a specific column. How would I specify this to say, column F within the sheet?

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());
}
Rubén
  • 34,714
  • 9
  • 70
  • 166

2 Answers2

1
function onEdit(e) {
   var range = e.range;

 // if you want to test a specific sheet, un-comment the following the following and move the range test inside this if   
/* if (range.getSheet().getName() === 'required sheet') {
    // do something
}*/

   if (range.getColumn() == 6) {// 6 is for col F

    range.setNote('Last modified: ' + new Date());

   }
}

This should work. It tests the column of the range if it is F (6 in this case) and sets the note.

Karan
  • 1,187
  • 2
  • 9
  • 16
0

To build on Karan's great answer. With this you can modify a row and update a column within the modified row.

function onEdit(e) {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getSheetByName('Sheet1')
   var row = e.range.getRow(); 

   // 'A' specifies the columns

   var range = sheet.getRange('A'+ row)
   Logger.log(range)
   range.setNote('Last modified: ' + new Date());

}
Jason Allshorn
  • 1,625
  • 1
  • 18
  • 27