从B15单元开始计算列B中的行数

我有以下代码,并且想要计算包含从单元格B15开始的数据行,B1到B14不会被统计。 无论如何修改代码来实现它?

Sub Macro1() Dim lastRow As Long With ActiveSheet Range("B15").Select lastRow = .Cells(.Rows.Count, "B").End(xlUp).Row MsgBox lastRow End With End Sub 

只需使用COUNTA的vba等价物,即

 MsgBox Application.CountA(Range("b15:b" & Rows.Count)) 

(也适用于该范围内的任何空白单元格)

尝试:

 Sub MyTest() Dim numRow As Long If IsEmpty(Cells(15, 2)) Then numRow = 0 Else numRow = Cells(Rows.Count, 2).End(xlUp).Row - 14 End If MsgBox numRow End Sub