Consulting

Results 1 to 5 of 5

Thread: Function to count values but not formulae

  1. #1
    VBAX Regular
    Joined
    Aug 2011
    Posts
    87
    Location

    Function to count values but not formulae

    I need a function that would count how many cells house any value but not consider cells with formula, in the used range.

    thanks in advance

  2. #2
    VBAX Regular
    Joined
    Dec 2007
    Posts
    21
    Location
    Perhaps like this

    [VBA]Sub CountVals()
    Dim c As Long
    c = ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants).Count
    MsgBox c
    End Sub
    [/VBA]

  3. #3
    VBAX Regular
    Joined
    Aug 2011
    Posts
    87
    Location
    Hi VoG. Thanks for reply.

    Is it possible to get the same result using a Function, I mean, using a UDF?

    thanks again

    Oswald

  4. #4
    VBAX Regular
    Joined
    Dec 2007
    Posts
    21
    Location
    Try this

    [VBA]Function CountVals(r As Range) As Long
    Dim c As Range
    For Each c In r
    If c.Value <> "" And Not c.HasFormula Then CountVals = CountVals + 1
    Next c
    End Function[/VBA]

    Then use it like

    =countvals(A1:J20)

  5. #5
    VBAX Regular
    Joined
    Aug 2011
    Posts
    87
    Location
    Hi VoG.
    Working fine. Thanks so much.
    Nice wknd.

    Oswald

Posting Permissions

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