Arun Venkitusamy
Arun Venkitusamy

Reputation: 47

Run only in a particular sheet specified by name

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.

Upvotes: 0

Views: 1012

Answers (1)

James D
James D

Reputation: 3142

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"

Upvotes: 2

Related Questions