I am 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:
function insCoDG(e) {
var ss = SpreadsheetApp.getActive()
var sheet = SpreadsheetApp.getActiveSheet()
var cell = sheet.getRange('bh6')
var cellContent = cell.getValue()
if(cellContent === "") {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getActiveSheet().hideColumns(60,1);
}
else {
if(cellContent !== "") {
var spreadsheet = SpreadsheetApp.getActive()
spreadsheet.getActiveSheet().showColumns(60, 1)
}
}
}