简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM