Kaio Neves
Kaio Neves

Reputation: 1

Hide columns based on a cell value google script

I just start learning about google script a few days ago and I'm facing one problem that I can't solve. In my google sheet I want to hide columns C-K if cell B2=FALSE and show columns C-K if cell B2=TRUE. How can I do that?

Upvotes: 0

Views: 2992

Answers (1)

Cooper
Cooper

Reputation: 64042

Add a checkbox to Cell B2 and use this simple onEdit function.

function onEdit(e) {
  var sh=e.range.getSheet();
  if(sh.getName()=='Sheet234' && e.range.columnStart==2 && e.range.rowStart==2) {
    e.source.toast(e.value);
    if(e.value=="TRUE") {
      sh.hideColumns(3,9);
    }else{
      sh.showColumns(3,9);
    }
  }  
}

Animation:

enter image description here

Upvotes: 3

Related Questions