How to run multiple script?

Jay Gabronino

Can anyone help me with these? I want all of it work but only the first one works.

function onEdit() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var mysheet = ss.getSheetByName("Sheet1");
  var activeCell = ss.getActiveCell().getA1Notation();

  if( activeCell == "A1" )
  {
    for(var i=0;i<50;i++)
    {
      if( i%2 == 0 )
        mysheet.getRange("A1:M1").setBackground("RED");
      else
        mysheet.getRange("A1:M1").setBackground("WHITE");

      SpreadsheetApp.flush();
      Utilities.sleep(500);
    }
  }
}


function onEdit1() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var mysheet = ss.getSheetByName("Sheet1");
  var activeCell = ss.getActiveCell().getA1Notation();

  if( activeCell == "A2" )
  {
    for(var i=0;i<50;i++)
    {
      if( i%2 == 0 )
        mysheet.getRange("A2:M2").setBackground("RED");
      else
        mysheet.getRange("A2:M2").setBackground("WHITE");

      SpreadsheetApp.flush();
      Utilities.sleep(500);
    }
  }
}

function onEdit2() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var mysheet = ss.getSheetByName("Sheet1");
  var activeCell = ss.getActiveCell().getA1Notation();

  if( activeCell == "A3" )
  {
    for(var i=0;i<50;i++)
    {
      if( i%2 == 0 )
        mysheet.getRange("A3:M3").setBackground("RED");
      else
        mysheet.getRange("A3:M3").setBackground("WHITE");

      SpreadsheetApp.flush();
      Utilities.sleep(500);
    }
  }
}

I want the 3 of it blink

CalamitousCode

If you want all three functions to run on edit, call them all from one function.

onEdit() {
    function1();
    function2();
    function3();
}

function1() {
    // Do something
}

function2() {
    // Do something
}

function3() {
    // Do something
}

EDIT

Here's a far shorter way to do all three:

function onEdit() {

    var spreadsheet = SpreadsheetApp.getActive();
    var sheet = spreadsheet.getActiveSheet();
    var cell = spreadsheet.getActiveCell();

    var col = cell.getColumn();
    var row = cell.getRow();

    if (col === 1 && sheet.getName() === 'Sheet1') {
    // If the edited cell is in column A (1) and on the correct sheet

        for (var num = 0; num < 50; num++) {

            var colour = num%2 === 0
                ? 'RED'
                : 'WHITE';
            // Using ? and : like this is called a ternary operation. It's a
            // shorter form of if. ifStatement ? true : false.

            sheet.getRange('A' + row + ':M' + row).setBackground(colour);
            // Get the range for the edited row and set the bg colour

            SpreadsheetApp.flush();
            Utilities.sleep(500);
        }
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to run remote script on multiple host simultaneously

How to run multiple .java files using shell script?

How to handle multiple https request to run a php script at same time?

How do you run multiple programs in parallel from a bash script?

How to run same script multiple times in ARM template?

How to run a script python on multiple files

How to run the same script multiple times without waiting for it to finish

How can I run a script on multiple folders

How to run multiple Python/Shell scripts from one script

Run multiple script in a container

How to run a script on multiple files matching a regex?

Run a script on multiple shells?

How to run a script in multiple instances ? ( Ubuntu server )

how to write a shell script to run multiple programs

Run script on multiple hosts

How to run script multiple times from command line?

How to start a gnome shell and run multiple commands from a script

How to run multiple config files through a script?

How to run a local script with a multiple-word argument on a remote server?

Run script on multiple files

How to run a standalone script on multiple google spreadsheets?

How to run python script for multiple input on multiple cores at the same time?

How to run multiple jars with an argument in a script

How to run a script multiple times

How to run a script multiple times in PHP

How to run perl script with multiple args from python script

How to run multiple scripts in a python script with args

How to run script multiple times for multiple variables?

how to run python script/file multiple times