Home > Enterprise >  Google Scripts / Sheets: How do I hide 3 cells based on the value of one cell?
Google Scripts / Sheets: How do I hide 3 cells based on the value of one cell?

Time:04-09

As a non-developer, could anyone advise on a script I could use to hide 3 cells based on what one cell says? Please see the sample spreadsheet Spreadsheet cells

CodePudding user response:

As enter image description here

When selecting Yes the row in Sheet2 will hide.

This is the script used:

var sheet = "Sheet1";
var editingsheet = "Sheet2";
var val = "Yes";
var column = 3;
function onEdit() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var activeSheet = SpreadsheetApp.getActiveSheet();
  var editingss = ss.getSheetByName(editingsheet);

  if(sheet == activeSheet.getName()){
    var cell = ss.getActiveCell();
    var cellnotation = cell.getA1Notation();
    var cvalue = cell.getValue();

    if(cell.getColumn() == column){
      if(cvalue == val){
        var range = editingss.getRange(cellnotation);
        editingss.hideRow(range);
      }
    }
  }
}

And this is the result that I get when selecting Yes on Funny item 1 and 12:

enter image description here

  • Related