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?

Excel VBA 最終行取得方法

Last updated at Posted at 2024-06-12

Excel VBA で最終行を取る時の書き方いろいろ【1】 自分メモ

1つめ End(xlUp)

Cells(Rows.Count, 指定列インデックス).End(xlUp).Row
Range("列"& Rows.Count).End(xlUp).Row
ピンポイントで列を指定できて、途中に空白セルがあっても問題がない
実務ではほぼこれを使っている

例) C列の最終行を取得する

Dim LastRow as Long
LastRow = Cells(Rows.Count,3).End(xlUp).Row
LastRow = Range("C" & Rows.Count).End(xlUp).Row

2つめ SpecialCells

Range("セル番地").SpecialCells(xlCellTypeLastCell).Row
この書き方も途中に空白セルがあっても問題ない
ただし、例えばA列からB列まで値が入っていると、B列の最終行をとる
ピンポイントで列を指定して最終行を取りたいときには不向き

例)

Dim LastRow as Long
LastRow = Range("A1").SpecialCells(xlCellTypeLastCell).Row
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?