1

I got this code on here but need to modify it so it only sees 3 sheets. 1 is Active Tickets. 2 is Closed Tickets. 3 is Pipeline. This is the code i currently have:

 function onEdit(event)
 {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var actSht = event.source.getActiveSheet();
var actRng = event.source.getActiveRange();

var index = actRng.getRowIndex();
var dateCol = actSht.getLastColumn();
var lastCell = actSht.getRange(index,dateCol);
var date = Utilities.formatDate(new Date(), "GMT-3", "dd/MM/yyyy HH:mm");

lastCell.setValue(date);
lastCell.setComment("Ultima Modificacion: " + actRng.getA1Notation() +' por     '+Session.getActiveUser());
ss.toast('Ultima Modificacion = '+ actRng.getA1Notation()+' por   '+Session.getActiveUser());
}

Any and all help would be much appreciated

  • Could you fix the formatting? As it stands, it is hard to read. – Vidar S. Ramdal Mar 14 '14 at 14:02
  • Sorry about that its been corrected now – Brutus Mar 14 '14 at 14:16
1

If I interpreted your question right you want your script run only if you edit a cell in one of the three sheets you mentioned.

You can use getName() on actSht to get the name of the sheet in which you have edited a cell. The you can just use an IF-statement to check if it's one of your sheets.

Here's an example of what I described above:

function onEdit(e) {
  var sheet = SpreadsheetApp.getActiveSheet();
  if (sheet.getName() == "Project" || sheet.getName() == "Tasks"){
    //Some code that only runs if the cell edited is in a sheet named "Projects" or "Tasks"
  }
}

And here's how you can apply it to your code:

function onEdit(event)
 {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var actSht = event.source.getActiveSheet();
    if(actSht.getName() == "Active Tickets" || actSht.getName() == "Closed Tickets" || actSht.getName() == "Pipeline"){

        var actRng = event.source.getActiveRange();

        var index = actRng.getRowIndex();
        var dateCol = actSht.getLastColumn();
        var lastCell = actSht.getRange(index,dateCol);
        var date = Utilities.formatDate(new Date(), "GMT-3", "dd/MM/yyyy HH:mm");

        lastCell.setValue(date);
        lastCell.setComment("Ultima Modificacion: " + actRng.getA1Notation() +' por     '+Session.getActiveUser());
        ss.toast('Ultima Modificacion = '+ actRng.getA1Notation()+' por   '+Session.getActiveUser());
    }
}

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.