Excel 如何获取工作表最后一行的行数

如题所述

请用VBA处理:

Sub Macro1()
Dim row_last As Long
Dim flag As Boolean, temp1 As Boolean, temp2 As Boolean
' 找出最后一行
Selection.SpecialCells(xlCellTypeLastCell).Select
flag = False
Do While flag = False
    If ActiveCell.Row = 1 Then
        Exit Do
    End If
    Selection.End(xlToLeft).Select
        temp1 = IsEmpty(ActiveCell.Value)
    Selection.End(xlToRight).Select
        temp2 = IsEmpty(ActiveCell.Value)
    If temp1 = True And temp2 = True Then
        Selection.Offset(-1, 0).Select
    Else
        flag = True
        Exit Do
    End If
Loop
Selection.End(xlToLeft).Select
row_last = ActiveCell.Row
End Sub

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-07-13
=ROWS(A:A)
相似回答