Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9624

*UPDATE* Hide/unhide certain columns on some conditions

$
0
0

UPDATE: I FIGURED IT OUT!!!! YEY!!!!

Im trying to have certain columns in my Google Sheet hide or unhide, depending on some conditions. I realized that this is difficult. But I've managed (I think) to come up with a way to make it work. The set up is, that when certain text in column A appears, I have a formula in another cell (a Heading cell) in another column, column B, that catches the text, and if it's Matched, then text appears (or stays blank if it's not matched).

Next, I have the following code, that reads that cell in column B, and if that cell is NOT BLANK, then the code UNHIDES the column (B); if the cell is BLANK, then the code HIDES the cell.

This works fine. However, it doesn't work in Order, and for some reason, for example, if the the code executes and UNHIDES the column, when running it again, it doesn't HIDE the column (the ELSE Statement)...it only hides it if I run the code from the Script Editor itself...by pressing the Play button...

This is my code:

FIGURED OUT CODE: Hides or Unhides columns based on conditions in cells

function onEdit(){
  var sheet = SpreadsheetApp.getActiveSheet().getSheetName()
  if(sheet === '🧩 CASE ASSEMBLY SHEET') {


 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('🧩 CASE ASSEMBLY SHEET');
 var cell = sheet.getRange('bh6');
 var cellContent = cell.getValue();

 if(cellContent === "") {
     var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('🧩 CASE ASSEMBLY SHEET');
  spreadsheet.hideColumns(60, 1);
}
  else {
    if(cellContent !== "") {
      var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('🧩 CASE ASSEMBLY SHEET');
     spreadsheet.showColumns(60, 1);
    }
}

 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('🧩 CASE ASSEMBLY SHEET');
 var cell = sheet.getRange('bi6');
 var cellContentt = cell.getValue();

 if(cellContentt === "") {
     var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('🧩 CASE ASSEMBLY SHEET');
  spreadsheet.hideColumns(61, 1);
}
  else {
    if(cellContentt !== "") {
      var spreadsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('🧩 CASE ASSEMBLY SHEET');
     spreadsheet.showColumns(61, 1);
    }
}

Viewing all articles
Browse latest Browse all 9624

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>