Home > Blockchain >  Hide Each Row That Doesn't Match The Current Week Plus The Next Twelve Rows
Hide Each Row That Doesn't Match The Current Week Plus The Next Twelve Rows

Time:02-02

Assuming today's date of Jan 26th, I have a Google Sheet I'm testing where column A rows 3, 15 and 27 have a dates entered (Jan 19th, Jan 26th and Feb 2nd). I'm trying to hide the Jan 19th and Feb 2nd rows (along with their next 12 rows respectively).

I found an older post/solution that works to hide the date row for only row 3 (Jan. 19th). I'm not certain how to adapt it to what I need. Any help would be appreciated.

function hideRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Sheet1");
var v = s.getRange("A:A").getValues();
var today = new Date();
today.setHours(0, 0, 0, 0);
for (var i = s.getLastRow(); i > 2; i--) {
    var t = v[i - 1];
    if (t != "") {
        var u = new Date(t);
        if (u < today) {
            s.hideRows(i);
        }
    }
}
Previous Weeks Date (Hide Me)
Hide Me 1
Hide Me 2
Hide Me 3
Hide Me 4
Hide Me 5
Hide Me 6
Hide Me 7
Hide Me 8
Hide Me 9
Hide Me 10
Hide Me 11
Hide Me 12
Current Week Date (Show Me)
Show Me 1
Show Me 2
Show Me 3
Show Me 4
Show Me 5
Show Me 6
Show Me 7
Show Me 8
Show Me 9
Show Me 10
Show Me 11
Show Me 12
Next Weeks Date (Hide Me)
Hide Me 1
Hide Me 2
Hide Me 3
Hide Me 4
Hide Me 5
Hide Me 6
Hide Me 7
Hide Me 8
Hide Me 9
Hide Me 10
Hide Me 11
Hide Me 12

Jerome

CodePudding user response:

Here's a solution I am using.

function hideRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Dude");       // Enter sheet name

var row = s.getRange('A2:A').getValues();  // Enter column letter that has the text "hide" and  "unhide"
var cell = s.getRange('A1').getValue();

s.showRows(1, s.getMaxRows());
for(var i=0; i < row.length; i  ){ if(row[i] != cell) { s.hideRows(i 2, 1); }   // Value to hide
     
}
}
  •  Tags:  
  • Related