Consulting

Results 1 to 2 of 2

Thread: Solved: Worksheet Function Compile Error

  1. #1
    VBAX Regular
    Joined
    Aug 2008
    Posts
    7
    Location

    Solved: Worksheet Function Compile Error

    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.

  2. #2
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    220
    Location
    Set it as a range

    [VBA]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
    [/VBA]
    "Intellectual passion occurs at the intersection of fact and implication."

    SGB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •