1

I am trying to hide rows when a cell says "Approved", this is what i have so far but it appears to be hiding all data even when "B:B" is "Pending"

 function ConditionalHideRow() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Sheet1");
  var condition = sheet.getRange("B:B").getValue();
  if (condition = "Approved") {
    sheet.hideRows(1,25)
   }   
   }
jhamon
  • 3,346
  • 3
  • 23
  • 35
Alexasks
  • 97
  • 6
  • 1
    Does this answer your question? [In javascript == vs =?](https://stackoverflow.com/questions/11871616/in-javascript-vs) – TheMaster Apr 08 '20 at 16:20

1 Answers1

0
function ConditionalHideRow() {
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getSheetByName("Sheet1");
  var values=sheet.getRange(1,2,sheet.getLastRow(),1).getValues();
  values.forEach(function(r,i){
    if(r[0]=='Approved') {
      sheet.hideRows(i+1)
    }
  });
}

Array.forEach()

Cooper
  • 36,005
  • 6
  • 17
  • 42
  • Thank you for your quick response, sorry new to scripting!, what does the [i] and [0] represent? @Cooper – Alexasks Apr 08 '20 at 16:37
  • Sorry I had to make an edit. I'm still a bit old school in my Javascript. But they are array indices. The getValues() method returns a two dimensional array. It's somewhat explained in the reference in my answer. – Cooper Apr 08 '20 at 16:44
  • Hello, Is there a way to update this to hide rows if collumn also states rejected, so only show blanks – Alexasks Apr 28 '20 at 13:31