我有3种方法可以找到col A中的最后一行。什么是差异?哪一个最好用。
Nr 1
Range("A" & Rows.Count).End(xlUp).Row
Nr 2
Cells.Find(What:="*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Nr 3
Dim Col, row, lastRow As Integer
Col = 1
row = 1
lastRow = 1
lastRow = Cells(Rows.Count, Col).End(xlUp).row
Cells(lastRow, Col).Select
答案 0 :(得分:0)
获取列 A 中最后一个已填充单元格的行号的一种方法:
Sub LastFilledCellInColumnA()
Dim wf As WorksheetFunction, nLastRowA As Long
Set wf = Application.WorksheetFunction
nLastRowA = Rows.Count
If wf.CountA(Cells(nLastRowA, 1)) = 1 Then
MsgBox nLastRowA
Exit Sub
End If
nLastRowA = Cells(Rows.Count, "A").End(xlUp).Row
MsgBox nLastRowA
End Sub
如果A列为空 1 将输出