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 3 years have passed since last update.

VBAでエクセルテーブルの最終行を取得する

Posted at

エクセルテーブルで最終行を取得する方法がわからなくなるので、自分用にまとめ

image.png

こんな感じのテーブルのデータが入っている最終行を取得したい
列数=4,テーブル行数=15,データの入っている最終行=10

一つ目、テーブルの最終行を取得して、その後テーブル内の最終行位置を取得する

test1
Sub test1()

Dim lastRow_Table As Long
Dim lastRow_A As Long

lastRow_Table = Cells(Rows.Count, 1).End(xlUp).Row
lastRow_A = Cells(lastRow_Table, 1).End(xlUp).Row

End Sub

二つ目 listobjectを使ってテーブルのA列からの中を上方向に検索かけて行って、最終行を探す

test2
Sub test2()

Dim lastRow_A As Long

lastRow_A = Cells(1).ListObject.Range.Columns(1).Cells.Find("*", searchdirection:=xlPrevious).Row

End Sub

もしお困りの方がいれば参考になれば幸いです

0
0
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
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?