Count the number of rows in another sheet

允我心安 提交于 2019-11-26 15:33:25
Paresh J

Check this and hope this will help you:

Sub verbflashcards()

Dim wordcount As Long

wordcount = ActiveWorkbook.Worksheets("Verbs").Range("A4", Worksheets("Verbs").Range("A4").End(xlDown)).Rows.Count

MsgBox (wordcount)

End Sub

Where, D1 is the column from which you can get row count.

Method 2:

Sub verbflashcards()

Dim wordcount As Long
With Sheets("Verbs")
    wordcount = .Range("A" & .Rows.Count).End(xlUp).Row
End With

MsgBox (wordcount)
End Sub

Note: There are lots of answers to your questions. Check this SO link: How can I find last row that contains data in the Excel sheet with a macro?

Your original was not working because the parent of Cells(4, 1) and Cells(4, 1).End(xlDown) was not specified. Prefix any cell address with a period (aka . or full stop) when you are inside a With ... End With block. Example:

With Worksheets("Verbs")
  wordcount = .Range(.Cells(4, 1), .Cells(4, 1).End(xlDown)).Rows.Count
End With

Note the .Cells(4, 1) and not Cells(4, 1). The period specifies that the cell(s) you are referring to are within Worksheets("Verbs").

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!