Robert Purves
Robert Purves

Reputation: 21

How do I get Google Script to hide rows with blanks or zeroes in a specific column, within a specific range of rows?

I'm new to coding, and this is my first question on stackoverflow.

I want to hide every row within a range of rows that has a blank or zero in a specific column, in this case, column D.

This is the code I'm currently using:

    var s = SpreadsheetApp.getActive().getSheetByName('Invoice Template');
        s.getRange('d:d')

It is hiding every row with a zero in it in the whole column, but I want it to hid only zeroes between rows 13 and 29.

Upvotes: 1

Views: 211

Answers (1)

TheBrenny
TheBrenny

Reputation: 527

var s = SpreadsheetApp.getActive()
     .getSheetByName('Invoice Template');

s.getRange('d13:d29') // Here's the fix!
     .getValues()
     .forEach(function (r, i) {
        if (r[0] !== '' && r[0].toString()
            .charAt(0) == 0) s.hideRows(i + 1)
    });

You're selecting the whole column in your code using s.getRange('d:d'). This should actually be s.getRange('d13:d29') to specify that you only want to process data between rows 13 and 29.

Upvotes: 1

Related Questions