How do I stop the for loop from continuing once the script (below) reaches the last row with data?
How do I get each group to collapse, instead of only the first one?
I'm not sure how to incorporate the .getLastRow()-1
into the script. I need the numRows
as 179 because that is the number of rows I want to group together, but just not sure how to finish the script. I modified one of the new "recorded macros" and worked backwards a bit. Additionally, the first group collapses as intended once it has been grouped, but the others are not. Any help would be appreciated!
function test2() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getActiveSheet();
var currentRow = 3;
var startColumn= 1;
var numRows = 179;
var numColumns= sheet.getMaxColumns();
for (i = 0; i < numRows; i++) {
sheet.getRange(currentRow, startColumn, numRows, numColumns).activate()
.shiftRowGroupDepth(1);
spreadsheet.getActiveSheet().getRowGroup(3, 1).collapse();
currentRow = currentRow+180
}
};
spreadsheet.getActiveSheet().getRowGroup(currentRow, 1).collapse();
– N.O.Davis