1

I'm just learning GAS and wrote the following for sheets. It is supposed to hide the row when the value in column c is zero. The script will run, but it does nothing to the sheet. What am I missing? BTW, I am planning on using this with an onChange trigger. I just rewrote it this way so that I could test it easily. I really appreciate any input!

function test() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Client");
  var range = sheet.getRange("C17:C67");
  var rangeValues = range.getValues();
  
  for (i = 0; i < range.length; i++) {
    if(rangeValues[1][i] == 0){
      sheet.hideRow(i+17);
    }
  }
}
yujiroads
  • 19
  • 2
  • It means the `if` condition is never satisfied. The reason the condition is not satisfied is because `rangeValues[1][i]` is using wrong index. Read the linked duplicate and practice 2D arrays. – TheMaster Dec 29 '20 at 07:33
  • Thanks. I learned more today and was able to get this script to somewhat work. rangeValues [ i ] [ 0 ] seems to be the answer. I did have to create an additional variable to make .hideRow functional. The only problem is that my script continues to loop. Are you able to say something that would help me understand why? My code now looks like the following... the log goes on a long ways after running this. Thanks. for (i = 0; i < 50; i++) { if(rangeValues[i][0] == 0){ var cell = sheet.getRange(i+17,3,1); sheet.hideRow(cell); Logger.log(rangeValues); – yujiroads Dec 30 '20 at 05:12
  • Hi... Glad that helped you. Aboutyour follow up question, We prefer 1 question => 1 answer style. Kindly ask a new question with [mcve] and ping me back. – TheMaster Dec 30 '20 at 06:03

0 Answers0