[VBA]最終行の列番号を取得する
最終行の列を取得するよ。以下コード
sheet1,A列の下から最終列取得して変数lastRowに挿入してMsgboxで出力する
Sub CommandButton1_Click()
Dim lastRow as long
With Worksheets("sheet1")
lastRow = .Cells(Rows.Count, 7).End(xlUp).Row
End With
Msgbox lastRow
End Sub
ポイントは ”.Cells(Rows.Count, 7).End(xlUp)”
Rows.Count が下から最終列、
7が最終行を調べる行番号になる
もし行に何も入っていない場合、一番上(1)が返ってきます。
以上
この記事が気に入ったらサポートをしてみませんか?