LoginSignup
3
6

More than 1 year has passed since last update.

GASで最終行を取得するメモ

Last updated at Posted at 2021-12-17

よく使うのにいつも忘れるのでメモ。

最終行と書いてますが、データが入っている最終行です。

function myFunction() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('シート1');

  const maxRng = sheet.getRange(sheet.getMaxRows(), 1);
  const lastRng = maxRng.getNextDataCell(SpreadsheetApp.Direction.UP);
  const lastRow = lastRng.getRow(); //データが入っている最終行

  console.log(lastRow);
}

(厳密な最終行、デフォルト1000件的なのを取得したいニーズってどれくらいあるんだろうか)

リテールでもスプレッドシート使いますよね?

ということでカレンダーに入れてみました。

参考

何回もこの記事にお世話になってる気がする。

【GAS】1行で書ける!特定列の最終行・特定行の最終列を取得する方法

3
6
1

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
3
6