I donβt know exactly what the problem is, because I cannot get your code to work as it is written. Two things seem obvious:
- You seem to rely on VBA to determine the types of variables and change them accordingly. This can be confusing if you are not careful, because VBA can assign a type to a variable that you did not plan. In your code,
myRange should be assigned to myRange . Since the Range type is an object in VBA, it must be Set , for example: Set myRange = Range("A:A") - Your use of the worksheet function
CountA() should be called using .WorksheetFunction
If you are not already doing this, consider using the Option Explicit option at the top of your module and typing variables using Dim statements, as I did below.
The following code works for me in 2010. Hope 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.
source share