Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

List rows that are not empty | appscript

To know the last row, you can use getLastRow()

I want something similar…

I need a function to get all non-empty rows

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In the table below, for example:

Test
OK
OK
OK
OK

The result I expect is: 1, 3, 4 and 6.

>Solution :

Here is a simple example of how to get non empty row numbers.

function getRows() {
  try {
    let spread = SpreadsheetApp.getActiveSpreadsheet();
    let sheet = spread.getSheetByName("Sheet1");
    let values = sheet.getDataRange().getValues();
    let filled = [];
    // note index is row number -1
    values.forEach( (row,index) => {
        if( row[0] !== "" ) filled.push(index);
      }
    );
    console.log(filled);
  }
  catch(err) {
    console.log(err);
  }
}

Execution log

8:23:45 AM  Notice  Execution started
8:23:47 AM  Info    [ 0, 1, 3, 4, 6 ]
8:23:46 AM  Notice  Execution completed

Reference

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading