Consulting

Results 1 to 4 of 4

Thread: Counting Cells Where Formula Does Not Return ""

  1. #1

    Counting Cells Where Formula Does Not Return ""

    Hello:

    I'm trying to count range cells where the formula in the cell does not return "". When using the following code, it counts all cells containing a formula regardless of the value returned.

    Sub CountNonBlankCells()
    Dim CellCount As Long
    CellCount = Application.WorksheetFunction.CountIf(Sheet2.Range("a1:k1"), "<>""")
    MsgBox CellCount, vbOKOnly
    End Sub
    If anyone knows how to count only cells where the formula returns something other than "" your help would be greatly appreciated!

    An example of what I'm trying to do is attached for reference.

    Thanks,


    Matt

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    CellCount = Application.WorksheetFunction.CountIf(Sheet2.Range("a1:k1"), "> """)

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    CellCount = Application.Evaluate("=SUMPRODUCT(--(LEN(A1:K1)>0))")
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thank you both for your help. Both formulas work perfectly!!

    Thank you very much!


    Matt

Posting Permissions

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