r/excel•
SCMAD

What would I change in this Hide Rows Google Sheets Script so that it instead Unhides Rows?

unsolved

Below is the script. I don't want a toggle "Hide/Unhide" button, I want one button to Hide (which I have), and one that will unhide all the rows in the same range.

Thanks for any help you can provide!

 function H5S() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("5S");
  var currentRange = ss.getRangeByName("A7:A100");
  var rangeStart = currentRange.getRow();
  var values = currentRange.getValues();

  var index = 0, rows = 1;
  var show = !(values[0][12] == "" );

  for (var i = 1, length = values.length; i < length; i++) {
    if (values[i][0] == 0 ) {
      if (show) {
        sheet.showRows(rangeStart + index, rows);
        show = false;
        index = i;
        rows = 1;
      } else
        rows++;
    } else {
      if (show)
        rows++;
      else {
        sheet.hideRows(rangeStart + index, rows);
        show = true;
        index = i;
        rows = 1;
      }
    }
  }

  if (show)
    sheet.showRows(rangeStart + index, rows);
  else
    sheet.hideRows(rangeStart + index, rows);
}

Posted Apr 18, 2019, 12:18 PM UTC

40

No comments yet

Nobody commented on this post, or the comments weren't captured.