PDA

View Full Version : Solved: Worksheet Function Compile Error



bob1122
08-25-2008, 09:13 AM
When I try to compile the following, I get a compile errer.

Sub metric()
kount = WorksheetFunction.Count(b:b)
MsgBox kount
End Sub

Excel will execute Count(b:b) and correctly count the number of rows in Column B that contain numeric data. The VBA compiler doesn't recognize the range (b:b) as valid. Is there another way to determine the count? Thanks.

Carl A
08-25-2008, 09:58 AM
Set it as a range

Sub metric()
Dim kount As Long
Dim myrange As Range
Set myrange = Worksheets("Sheet1").Range("B:B")
kount = WorksheetFunction.Count(myrange)
MsgBox kount
End Sub