0

The below code works for Q3 but not for Q5. I'm relatively new to sheets and writing code and I'm sure that you can't have two functions with the same name but am unsure how to resolve so that I can edit and move multiple rows. Any help would be greatly appreciated.

/** @OnlyCurrentDoc */

function onEdit(e) {
  var range = e.range;
  if (e.range.getA1Notation() == 'Q3') 
  {
    MoveData_19();
  }
}
function MoveData_19() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('F3:N4').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Completed Loads'), true);
  spreadsheet.getRange('B1').activate();
  spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
  spreadsheet.getRange('\'Dayshift Dispatch\'!F3:N4').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Dayshift Dispatch'), true);
  spreadsheet.getRange('H3:N3').activate();
  spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
}

function onEdit(e) {
  var range = e.range;
  if (e.range.getA1Notation() == 'Q5') 
 {
    MoveData_20();
  }
}
function MoveData_20() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('F5:N6').activate();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Completed Loads'), true);
  spreadsheet.getRange('B1').activate();
  spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
  spreadsheet.getRange('\'Dayshift Dispatch\'!F5:N6').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Dayshift Dispatch'), true);
 spreadsheet.getRange('H5:N5').activate();
  spreadsheet.getActiveRangeList().clear({contentsOnly: true, skipFilteredRows: true});
}
0

This is how you should run multiple onEdit scripts:

function onEdit(e) {
   oneditfx1(e);
   oneditfx2();
   }
oneditfx1(e) { //start of code if(condition == met) { //operation to follow } //closes if statement operations
oneditfx2() { //start of code if(condition == met){ //operation to follow } }

  • Thank you. I came up with this as well and it worked. Is there a reason why yours would be more efficient? function onEdit(e) { var range = e.range; if (e.range.getA1Notation() == 'Q3') { MoveData_3(); } else if(e.range.getA1Notation() == 'Q5') { MoveData_5(); } – Steve Jul 23 at 14:19
  • @Steve you are welcome. nope, nor of these approaches are superior. it's a matter of liking – user0 Jul 23 at 14:38

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.