简体   繁体   中英

How to select all rows on Google Sheets using Google Apps Script?

I want to delete all the rows that I don't need on Google Sheets, my data has a table header.

Thanks!

I believe your goal as follows.

  • You want to select all rows using Google Apps Script.

In this case, how about the following sample script?

Sample script:

function muFunction() {
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("C:C").activate();
}
  • When this script is run, the column "C" of "Sheet1" is selected.
  • For example, when "C:C" is modified to "C2:C", the cells "C2:C" are selected.

Note:

  • From I want to delete all the rows that I don't need on Google Sheets, my data has a table header. , when you want to clear the rows except for the 1st header row, you can also use the following script. When the following script is run, the cells "C2:C" of "Sheet1" are cleared.

     function muFunction2() { SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("C2:C").clearContent(); }
  • From What's the code equivalent for Command + shift + down? , in this case, I thought that the following script is the result you expect? When you use the following script, please select a cell and run the script. By this, the rows of the data range after the selected cell are selected.

     function myFunction3() { const activeRange = SpreadsheetApp.getActiveRange(); activeRange.offset(0, 0, activeRange.getNextDataCell(SpreadsheetApp.Direction.DOWN).getRow() - activeRange.getRow() + 1).activate(); }

References:

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