0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

スプレッドシートの最終行を取得する

Posted at

最終行を取得するには

let lastRow = sheet.getLastRow();

これがシンプルですが、シート全体の最終行をとってしまうので

特定の列を指定したい場合、例えばA列の最終行をとりたいとすると


function codeForGetRow() {  
  let range = sheet.getRange(1, 1).getNextDataCell(SpreadsheetApp.Direction.DOWN);
  let lastRow = range.getRow();
  return lastRow
}

途中に空白があるが、最終行を取りたい場合

function myFunction() {  
  var lastRow = sheet.getRange(sheet.getMaxRows(), 1).getNextDataCell(SpreadsheetApp.Direction.UP).getRow();
  Logger.log(lastRow);   
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?