2
votes

I have these scripts working separately but when I combine them or create two different scripts only one will function. If found that the conditional formatting tool was bogging down my spreadsheet, so I used the first script to replace that function and it made all the difference. The second script is simply an archive script to move the row to an archive sheet. Only one will function at a time, no matter who I combine them. I've tried two separate scripts and I tried combining. Including changing the name of the function so. What am I missing?

function onEdit(e) {
if (e) { 
    var ss = e.source.getActiveSheet();
    var r = e.source.getActiveRange(); 

        // E.g. status column is 2nd (B)
        status = ss.getRange(r.getRow(), 2).getValue();

        // Specify the range with which You want to highlight
        // with some reading of API you can easily modify the range selection properties
        // (e.g. to automatically select all columns)
        rowRange = ss.getRange(r.getRow(),3,1,8);

        // This changes font color
        if (status == 'Complete') {
            rowRange.setFontColor("#d3d3d3");
            rowRange.setBackgroundColor("#FFFFFF");
        } else if (status == 'This Week') {
            rowRange.setFontColor("#000000");
            rowRange.setBackgroundColor("#ACE5A2");
        } else if (status == 'Next Week') { 
            rowRange.setFontColor("#000000");
            rowRange.setBackgroundColor("#D3D8D9");
        } else if (status == 'Priority') { 
            rowRange.setFontColor("#FFFF11");
            rowRange.setBackgroundColor("#1997F6");
        } else if (status == 'Late') { 
            rowRange.setFontColor("#D92B14");
            rowRange.setBackgroundColor("#FFFFFF");
        } else if (status == '') { 
            rowRange.setFontColor("#000000");
            rowRange.setBackgroundColor("#FFFFFF");
        }   
    }
}

function onEditArchive() {

var sheetsToWatch= ["Valley","DBWC","Genus Heart","Mutli 
Run","ECM","MRE","Medella","Mitro"];


var columnNumberToWatch = 10; // column A = 1, B = 2, etc.
var valueToWatch = "Archive";
var sheetNameToMoveTheRowTo = "Archive";

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();


if (sheetsToWatch && range.getColumn() == columnNumberToWatch && 
range.getValue() == valueToWatch) {

var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 
1);
    sheet.getRange(range.getRow(), 1, 1, 
sheet.getLastColumn()).moveTo(targetRange);
    sheet.deleteRow(range.getRow());
  }
}
1

1 Answers

4
votes

Got an answer from Two OnEdit functions not working together

In short, I renamed the second OnEditArchive to OnEdit2 and then went to Edit > Current Project Triggers and set up each individual OnEdit to be triggered on edit.

Hope that helps!