2016-08-02 28 views
0

現在我可以用得到VBA填充了值的行數:得到填補在特定列的行數-VBA

Rows(Rows.Count).End(xlUp).Row 

但是這條線只讓我排在第一個的數量柱。我會做什麼來得到相同的,但對於任何給定的列?

謝謝。

編輯:答案簡單地使列作爲行的參數()

+3

'細胞(Rows.Count,colNumOrLetterHere).END(xlUp).Row' –

+0

感謝添!接受的答案 –

回答

0
Debug.Print Range("A1").SpecialCells(xlCellTypeLastCell).Row 

上述行說,沒有在當前片使用的行。

0

問題是如何獲取特定列中填充行的數量。這與獲取列中最後一次使用的行號不同。

這裏是如何計算有多少非空白單元格的列

WorksheetFunction.CountA(Columns(2))

的方法有很多細胞的參考範圍。下面是一些例子:

Sub Examples() 

    Debug.Print "The last used row in the second column" 
    Debug.Print Columns(2).Rows(Rows.Count).End(xlUp).row 
    Debug.Print 
    Debug.Print "The last used row in the second column" 
    Debug.Print Columns("B").Rows(Rows.Count).End(xlUp).row 
    Debug.Print 
    Debug.Print "The last used row in the second column using Find" 
    Debug.Print Columns("B").Find(What:="*", SearchDirection:=xlPrevious).row 
    Debug.Print 
    Debug.Print "The last used row on the ActiveSheet using Find" 
    Debug.Print Cells.Find(What:="*", SearchDirection:=xlPrevious).row 
    Debug.Print 
    Debug.Print "The last used row in the second column" 
    Debug.Print Cells(Rows.Count, 2).End(xlUp).row 
    Debug.Print 
    Debug.Print "The last used row in the second column" 
    Debug.Print Cells(Rows.Count, "B").End(xlUp).row 
    Debug.Print 
    Debug.Print "The last used row in the second column" 
    Debug.Print Range("B" & Rows.Count).End(xlUp).row 
    Debug.Print 
    Debug.Print "The last used row on the ActiveSheet, this is not limited to Column A" 
    Debug.Print Range("A1").SpecialCells(xlCellTypeLastCell).row 

    Debug.Print 
    Debug.Print "The number of non-blank cells in Column B" 
    Debug.Print WorksheetFunction.CountA(Columns(2)) 

End Sub