I'm not sure exactly what your problem is, because I cannot get your code to work as written. Two things seem evident:
Range
should be assigned to myRange
. Since a Range
type is an object in VBA it needs to be Set
, like this: Set myRange = Range("A:A")
CountA()
should be called with .WorksheetFunction
If you are not doing it already, consider using the Option Explicit option at the top of your module, and typing your variables with Dim
statements, as I have done below.
The following code works for me in 2010. Hopefully it works for you too:
Dim myRange As Range
Dim NumRows As Integer
Set myRange = Range("A:A")
NumRows = Application.WorksheetFunction.CountA(myRange)
Good Luck.