I have a working script that hides rows in multiple tabs of a Google Sheet based on the value in Column T (note, there are more tabs in the sheet that I don't want it to work from - just the ones in the script). My issue is, it unhides all of the hidden rows first and then re-hides them including the new one...is there an adaptation I can make to the script so that it leaves all the currently hidden rows hidden and just hides the newly updated one?
function hideRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var only = ['Franke Fault', 'Selecta Vending Machines', 'Vivreau'
];
if (only.indexOf(ss.getName()) == -1) return;
var r = ss.getRange('T:T');
var v = r.getValues();
for(var i=v.length-1;i>=0;i--)
if (v[0, i] > 10)
ss.hideRows(i 1);
};
Thank you, any help would be greatly appreciated
CodePudding user response:
Try it this way: I tested this and works for me
function hideRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var only = ['Franke Fault', 'Selecta Vending Machines', 'Vivreau','Sheet0' ];
if (~only.indexOf(ss.getName())) {
var v = ss.getRange(1, 20, ss.getLastRow()).getValues();
v.forEach((r, i) => {
if (r[0] > 10) {
ss.hideRows(i 1)
}
});
}
}
Before:
COL20 |
---|
5 |
15 |
3 |
5 |
1 |
3 |
7 |
2 |
12 |
4 |
6 |
17 |
0 |
4 |
0 |
7 |
2 |
2 |
19 |
9 |
After:
COL20 |
---|
5 |
3 |
5 |
1 |
3 |
7 |
2 |
4 |
6 |
0 |
4 |
0 |
7 |
2 |
2 |
9 |
Keep in mind it hides them but it does not remove them if you try to copy and paste the then you will get all of the data and not just the hidden ones