0

So I have 3 separate sheets in on Google Sheet Doc, I have a script running on the first sheet that hides a row when a drop down is ammended:

var SHEET = "Tweaks Needed";
var VALUE = "All Tweaks Made";
var COLUMN_NUMBER = 7

function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeSheet = ss.getActiveSheet();

if(SHEET == activeSheet.getName()){
  var cell = ss.getActiveCell()
  var cellValue = cell.getValue();

  if(cell.getColumn() == COLUMN_NUMBER){
    if(cellValue == VALUE){
      activeSheet.hideRow(cell);
   };
  };
 }; 
}

I have then generated a second script as follows:

var SHEET = "Standalone";
var VALUE = "Correct";
var COLUMN_NUMBER = 5

function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var activeSheet = ss.getActiveSheet();

  if(SHEET == activeSheet.getName()){
    var cell = ss.getActiveCell()
    var cellValue = cell.getValue();

    if(cell.getColumn() == COLUMN_NUMBER){
      if(cellValue == VALUE){
        activeSheet.hideRow(cell);
      };
    };
  };
}

When I add this second script, it completely overrides the first one, causing it to not function. I do have a third script however this is the same concept.

Is there a way to combine these two scripts so that both work accordingly?

0

onEdit scripts are per google sheet documents, not per individual tab/spreadsheet. You should change your flow so that it follows something like this:

function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var activeSheet = ss.getActiveSheet();

  if("Standalone" == activeSheet.getName()){
    // logic for sheet Standalone       
  } else if ("Tweaks Needed" == activeSheet.getName()) {
    // logic for sheet Teaks Needed
  }
};
  • Perfect, I'm new to this but assumed there must be a way! Thanks – Sam Dec 11 '18 at 10:56

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.