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で最終行を取得する

Last updated at Posted at 2020-08-30

VBAで最終行を取得する

範囲指定や入力セルの指定には、対象の列の最終行番号を取得して使用します。

最終行を取得

Sub 最終行を取得()
    Dim LastRow As Long
    LastRow = ThisWorkbook.Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    Debug.Print LastRow
End Sub

image.png
image.png

最終行のひとつ下から入力させたい場合は

Sub 最終行を取得してひとつ下に値を入力()
    Dim LastRow As Long
    LastRow = ThisWorkbook.Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
    ThisWorkbook.Worksheets("Sheet1").Cells(LastRow + 1, 1).Value = 10
    ThisWorkbook.Worksheets("Sheet1").Cells(LastRow + 1, 2).Value = "jjj"
End Sub

image.png

ワタシ流こだわり

ThisWorkbook.Worksheets("Sheet1") や__シートオブジェクト名__は絶対つける:point_up:

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?