2
votes

I would like to fire a trigger with onEdit if a event (edit a cell) happens in a specific range of a Sheet (NOT all Sheet)? Exemple: I only want to trigger if a cell of the range called "trgRng" (C10:C250) of Sheet_1 is edited.

I coded as below, but it trigger all sheets not only a specific range of a specific sheet

function onEdit(e) {
   var ss = SpreadsheetApp.getActiveSpreadsheet();

   // source sheet
   var sSh = ss.getSheetByName("Diario");  
   var aCell = sSh.getActiveCell().getValue();

   // destiny sheet - set value from source sheet
   var dSh = ss.getSheetByName("Auxiliar");
   dSh.getRange('L4').setValue(aCell);
}

Is it possible? How?

1

1 Answers

3
votes

I already solve it:

{
function onEdit(e) {
    var ss = SpreadsheetApp.getActiveSpreadsheet();

    // source sheet
    var sSh = e.source.getActiveSheet();
    var maxRow = sSh.getMaxRows();
    var name = sSh.getName();  

    var rng = e.range;
    var rngCol = rng.getColumn();

    if (sSh.getName() == "Diário" && rng.getColumn() == 8) {

        ss.getSheetByName("Diário");  
        var aCell = sSh.getActiveCell().getValue();

        // target sheet
        var shD = ss.getSheetByName("Auxiliar");
        shD.getRange('L4').setValue(aCell);
    }
  }
}