I have the following code which is for tracking the date of any edit made in a particular row. However, this code applies to the whole spreadsheet file, I would like to change this to be for the 1st sheet only which is titled "Deals List". Can anyone help please?

function onEdit() {
var dateColNum = 7 //column G
var ss1 = SpreadsheetApp.getActiveSpreadsheet();

//set date in same row as edit happens, at fixed column  
ss1.getActiveSheet().getRange(ss1.getActiveRange().getLastRow(), dateColNum, 1, 1).setValue(new Date())

Add something like the following

If by "first sheet" you mean one specific sheet no matter the sheets order

if(ss1.getSheetName() == 'Sheet1'){
  //do something like set date


If by "first sheet" you mean that the sheets' order matters

if(SpreadsheetApp.getSheets()[0].getSheetName() === ss1.getSheetName()){
  //do something like set date

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.