0

all

If you put the two together they don't work What is the right code to work together Note that the first to arrange automatic The second is to set the date if you put only one works, but if you add the other all stops working

function onEdit(event){
  var sheet = event.source.getActiveSheet();
  var editedCell = sheet.getActiveCell();

  var columnToSortBy = 13;
  var tableRange = "A2:Y";

  if(editedCell.getColumn() == columnToSortBy){   
    var range = sheet.getRange(tableRange);
    range.sort( { column : columnToSortBy } );
  }
}


{
function onEdit(e) {
var sh = e.source.getActiveSheet();
var sheets = [];
var ind = [2].indexOf(e.range.columnStart);
  var stampCols = [13]


if(sheets.indexOf(sh.getName()) ==-1 || ind == -1) return;
sh.getRange(e.range.rowStart, stampCols[ind]).setValue(typeof e.value == 'object' ? null : new Date )


}
}

sheet test https://drive.google.com/open?id=1mFqHdeF6l25XeyIOXwcdKqnYC27BrvZd1MaskHNAdJc

1
function onEdit(e){

 onEdit1(e);

  var sheet = event.source.getActiveSheet();
  var editedCell = sheet.getActiveCell();

  var columnToSortBy = 13;
  var tableRange = "A2:Y";

  if(editedCell.getColumn() == columnToSortBy){   
    var range = sheet.getRange(tableRange);
    range.sort( { column : columnToSortBy } );


  onEdit2(e);

var sh = e.source.getActiveSheet();
var sheets = [];
var ind = [13].indexOf(e.range.columnStart);
  var stampCols = [2]

if(sheets.indexOf(sh.getName()) ==-1 || ind == -1) return;
sh.getRange(e.range.rowStart, stampCols[ind]).setValue(typeof e.value == 'object' ? null : new Date )


}
}

https://docs.google.com/spreadsheets/d/1mFqHdeF6l25XeyIOXwcdKqnYC27BrvZd1MaskHNAdJc/edit#gid=1945346364

0

In simple words, functions names should be unique on each Google Apps Script project. Let say that you want to follow the easier path, to do this:

  1. Change the functions names, to something like onEdit1 and onEdit2
  2. Add an onEdit function that will call the previous renamed functions

    function onEdit(e){
      onEdit1(e);
      onEdit2(e);
    }
    
  • thank you for answer But i try but not working or i make mistake can you help me more type full code ! – Ibrahim kamal Aug 22 at 12:50
  • @Ibrahimkamal Please edit your question to show your progress including the steps you followed to test the code and the execution transcript. – Rubén Aug 22 at 15:04

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.