0

I'm trying to auto populate editor's name or email in a specified cell while they editing a value in that row.

why because, If a sheet is shared among N' number of people and there multiple users will enter data. At that scenario I need to know by whom a particular data was entered.

I write a Google apps script, but it's working on all sheets. i need it to run only in a particular sheet named "Purchase".

function onEdit(e) 
{ 
  var editedRange = e.range; 
  if ( editedRange.getColumn()==1 ) 
  { // if column A was edited 
    var u = Session.getActiveUser().getEmail(); 
    editedRange.offset(0, 13).setValue(u); // write user's email to corresponding row in column N 
  } 
};

my sheet will be like this.

Rubén
  • 34,714
  • 9
  • 70
  • 166

1 Answers1

2

Add a second parameter to your IF to check the sheet name

 if ( editedRange.getColumn()==1 && e.source.getActiveSheet().getName() == "Purchase";

This will return true IF the edited cell is in col 1 and (&&) the active sheet is named "Purchase"

James D
  • 3,102
  • 1
  • 11
  • 21
  • Mr. James Donnellanm, Thanks. Only while I'm using this script my email is printed in respective cell. If the same sheet is edited by another shared user the script is not working. Can you kindly clarify me. – Arun Venkitusamy Feb 10 '18 at 08:11
  • 1
    You will need to use an installed trigger. See my answer [here](https://stackoverflow.com/questions/45155847/google-script-project-trigger-not-running/45157034#45157034) it's about the onSubmit trigger but just change the onSubmit to onEdit and you should be good to go. – James D Feb 10 '18 at 08:50