Reputation: 65
How to hide rows based on current selected cell? I always need to hide 4 rows from the 5th row down based on the selected cell.
I tried to make the following code:
function hidelines() {
var ss = SpreadsheetApp.getActive();
ss.getActiveRange().getNumRows();
ss.getActiveSheet().hideRows(10, 4);
};
But he's always hiding from line 10. Is there any way to be based on the cell that I'm selected? Ex: if I'm on line 19, hide the lines 23 to 26? See that detected that I'm on line 19, counted 5 lines down, and hid 4 lines.
Upvotes: 0
Views: 56
Reputation: 64110
Try this:
function hideFourFromFifth() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var cell=sh.getActiveCell();
var row=cell.getRow();
sh.hideRows(row + 5, 4);
}
This one might be more useful:
function hideRowsFromOffset(offset,rows) {
var offset=offset || 4;//if you're on 19 this will hide 23 to 26
var rows=rows || 4;
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet();
var cell=sh.getActiveCell();
var row=cell.getRow();
sh.hideRows(row + offset, rows);
}
Upvotes: 1