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
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.
Comments